17405867cSopenharmony_ci/* 27405867cSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 37405867cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47405867cSopenharmony_ci * you may not use this file except in compliance with the License. 57405867cSopenharmony_ci * You may obtain a copy of the License at 67405867cSopenharmony_ci * 77405867cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87405867cSopenharmony_ci * 97405867cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107405867cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117405867cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127405867cSopenharmony_ci * See the License for the specific language governing permissions and 137405867cSopenharmony_ci * limitations under the License. 147405867cSopenharmony_ci */ 157405867cSopenharmony_ci 167405867cSopenharmony_ci#include "hiappevent_native_test.h" 177405867cSopenharmony_ci 187405867cSopenharmony_ci#include <cstring> 197405867cSopenharmony_ci#include <string> 207405867cSopenharmony_ci#include <vector> 217405867cSopenharmony_ci 227405867cSopenharmony_ci#include "hiappevent/hiappevent.h" 237405867cSopenharmony_ci#include "hiappevent_base.h" 247405867cSopenharmony_ci#include "hiappevent_config.h" 257405867cSopenharmony_ci#include "hiappevent_userinfo.h" 267405867cSopenharmony_ci#include "ndk_app_event_processor_service.h" 277405867cSopenharmony_ci#include "time_util.h" 287405867cSopenharmony_ci 297405867cSopenharmony_ciusing namespace testing::ext; 307405867cSopenharmony_ciusing namespace OHOS::HiviewDFX; 317405867cSopenharmony_ci 327405867cSopenharmony_cinamespace { 337405867cSopenharmony_ciconst std::string TEST_STORAGE_PATH = "/data/test/hiappevent/"; 347405867cSopenharmony_ciconst char* TEST_DOMAIN_NAME = "test_domain"; 357405867cSopenharmony_ciconst char* TEST_EVENT_NAME = "test_event"; 367405867cSopenharmony_ciconst char* TEST_EVENT_PARAM_KEY = "test_param_key"; 377405867cSopenharmony_ciconst char* TEST_EVENT_PARAM = "{\"test_param_key\":1}"; 387405867cSopenharmony_ciconstexpr int TEST_EVENT_PARAM_LENGTH = 20; 397405867cSopenharmony_ciconstexpr int TEST_EVENT_NUM = 2; 407405867cSopenharmony_ci 417405867cSopenharmony_ciconst char* TEST_PROCESSOR_NAME = "test_processor"; 427405867cSopenharmony_ciconstexpr int32_t TEST_UID = 200000 * 100; 437405867cSopenharmony_ci 447405867cSopenharmony_cistatic void WriteEvent() 457405867cSopenharmony_ci{ 467405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 477405867cSopenharmony_ci OH_HiAppEvent_AddInt16Param(list, TEST_EVENT_PARAM_KEY, 1); 487405867cSopenharmony_ci OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, SECURITY, list); 497405867cSopenharmony_ci} 507405867cSopenharmony_ci 517405867cSopenharmony_cistatic void OnReceive(const char* domain, const struct HiAppEvent_AppEventGroup* appEventGroups, uint32_t groupSize) 527405867cSopenharmony_ci{ 537405867cSopenharmony_ci ASSERT_EQ(strcmp(domain, TEST_DOMAIN_NAME), 0); 547405867cSopenharmony_ci ASSERT_EQ(groupSize, 1); 557405867cSopenharmony_ci ASSERT_TRUE(appEventGroups); 567405867cSopenharmony_ci ASSERT_EQ(appEventGroups[0].infoLen, 1); 577405867cSopenharmony_ci ASSERT_TRUE(appEventGroups[0].appEventInfos); 587405867cSopenharmony_ci ASSERT_EQ(strcmp(appEventGroups[0].appEventInfos[0].name, TEST_EVENT_NAME), 0); 597405867cSopenharmony_ci ASSERT_EQ(strcmp(appEventGroups[0].appEventInfos[0].domain, TEST_DOMAIN_NAME), 0); 607405867cSopenharmony_ci ASSERT_EQ(appEventGroups[0].appEventInfos[0].type, SECURITY); 617405867cSopenharmony_ci ASSERT_EQ(strncmp(appEventGroups[0].appEventInfos[0].params, TEST_EVENT_PARAM, TEST_EVENT_PARAM_LENGTH), 0); 627405867cSopenharmony_ci} 637405867cSopenharmony_ci 647405867cSopenharmony_cistatic void OnTrigger(int32_t row, int32_t size) 657405867cSopenharmony_ci{ 667405867cSopenharmony_ci ASSERT_EQ(row, TEST_EVENT_NUM); 677405867cSopenharmony_ci ASSERT_GT(size, 0); 687405867cSopenharmony_ci} 697405867cSopenharmony_ci 707405867cSopenharmony_cistatic void OnTake(const char* const *events, uint32_t eventLen) 717405867cSopenharmony_ci{ 727405867cSopenharmony_ci ASSERT_TRUE(events != nullptr); 737405867cSopenharmony_ci ASSERT_EQ(eventLen, TEST_EVENT_NUM); 747405867cSopenharmony_ci} 757405867cSopenharmony_ci 767405867cSopenharmony_cistd::string GetStorageFilePath() 777405867cSopenharmony_ci{ 787405867cSopenharmony_ci return "app_event_" + TimeUtil::GetDate() + ".log"; 797405867cSopenharmony_ci} 807405867cSopenharmony_ci} 817405867cSopenharmony_ci 827405867cSopenharmony_civoid HiAppEventNativeTest::SetUpTestCase() 837405867cSopenharmony_ci{ 847405867cSopenharmony_ci // set app uid 857405867cSopenharmony_ci setuid(TEST_UID); 867405867cSopenharmony_ci HiAppEventConfig::GetInstance().SetStorageDir(TEST_STORAGE_PATH); 877405867cSopenharmony_ci} 887405867cSopenharmony_ci 897405867cSopenharmony_ci/** 907405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest001 917405867cSopenharmony_ci * @tc.desc: check the logging function 927405867cSopenharmony_ci * @tc.type: FUNC 937405867cSopenharmony_ci * @tc.require: AR000GIKMA 947405867cSopenharmony_ci */ 957405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest001, TestSize.Level0) 967405867cSopenharmony_ci{ 977405867cSopenharmony_ci /** 987405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 997405867cSopenharmony_ci * @tc.steps: step2. add params to the ParamList. 1007405867cSopenharmony_ci * @tc.steps: step3. write event to the file. 1017405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 1027405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 1037405867cSopenharmony_ci */ 1047405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 1057405867cSopenharmony_ci bool boolean = true; 1067405867cSopenharmony_ci OH_HiAppEvent_AddBoolParam(list, "bool_key", boolean); 1077405867cSopenharmony_ci bool booleans[] = {true, false, true}; 1087405867cSopenharmony_ci OH_HiAppEvent_AddBoolArrayParam(list, "bool_arr_key", booleans, sizeof(booleans) / sizeof(booleans[0])); 1097405867cSopenharmony_ci int8_t num1 = 1; 1107405867cSopenharmony_ci OH_HiAppEvent_AddInt8Param(list, "int8_key", num1); 1117405867cSopenharmony_ci int8_t nums1[] = {1, INT8_MIN, INT8_MAX}; 1127405867cSopenharmony_ci OH_HiAppEvent_AddInt8ArrayParam(list, "int8_arr_key", nums1, sizeof(nums1) / sizeof(nums1[0])); 1137405867cSopenharmony_ci int16_t num2 = 1; 1147405867cSopenharmony_ci OH_HiAppEvent_AddInt16Param(list, "int16_key", num2); 1157405867cSopenharmony_ci int16_t nums2[] = {1, INT16_MAX, INT16_MIN}; 1167405867cSopenharmony_ci OH_HiAppEvent_AddInt16ArrayParam(list, "int16_arr_key", nums2, sizeof(nums2) / sizeof(nums2[0])); 1177405867cSopenharmony_ci int32_t num3 = 1; 1187405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, "int32_key", num3); 1197405867cSopenharmony_ci int32_t nums3[] = {1, INT32_MAX, INT32_MIN}; 1207405867cSopenharmony_ci OH_HiAppEvent_AddInt32ArrayParam(list, "int32_arr_key", nums3, sizeof(nums3) / sizeof(nums3[0])); 1217405867cSopenharmony_ci int64_t num4 = 1; 1227405867cSopenharmony_ci OH_HiAppEvent_AddInt64Param(list, "int64_key", num4); 1237405867cSopenharmony_ci int64_t nums4[] = {1LL, INT64_MAX, INT64_MIN}; 1247405867cSopenharmony_ci OH_HiAppEvent_AddInt64ArrayParam(list, "int64_arr_key", nums4, sizeof(nums4) / sizeof(nums4[0])); 1257405867cSopenharmony_ci float num5 = 465.1234; 1267405867cSopenharmony_ci OH_HiAppEvent_AddFloatParam(list, "float_key", num5); 1277405867cSopenharmony_ci float nums5[] = {123.22f, num5, 131312.46464f}; 1287405867cSopenharmony_ci OH_HiAppEvent_AddFloatArrayParam(list, "float_arr_key", nums5, sizeof(nums5) / sizeof(nums5[0])); 1297405867cSopenharmony_ci double num6 = 465.1234; 1307405867cSopenharmony_ci OH_HiAppEvent_AddDoubleParam(list, "double_key", num6); 1317405867cSopenharmony_ci double nums6[] = {123.22, num6, 131312.46464}; 1327405867cSopenharmony_ci OH_HiAppEvent_AddDoubleArrayParam(list, "double_arr_key", nums6, sizeof(nums6) / sizeof(nums6[0])); 1337405867cSopenharmony_ci char str1[] = "hello"; 1347405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, "str_key", str1); 1357405867cSopenharmony_ci char str2[] = "world"; 1367405867cSopenharmony_ci char* strs[] = {str1, str2}; 1377405867cSopenharmony_ci OH_HiAppEvent_AddStringArrayParam(list, "str_arr_key", strs, sizeof(strs) / sizeof(strs[0])); 1387405867cSopenharmony_ci 1397405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, BEHAVIOR, list); 1407405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 1417405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 1427405867cSopenharmony_ci} 1437405867cSopenharmony_ci 1447405867cSopenharmony_ci/** 1457405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest002 1467405867cSopenharmony_ci * @tc.desc: check the overwriting function of the same param name. 1477405867cSopenharmony_ci * @tc.type: FUNC 1487405867cSopenharmony_ci * @tc.require: AR000GIKMA 1497405867cSopenharmony_ci */ 1507405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest002, TestSize.Level0) 1517405867cSopenharmony_ci{ 1527405867cSopenharmony_ci /** 1537405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 1547405867cSopenharmony_ci * @tc.steps: step2. add params with the same name to the ParamList. 1557405867cSopenharmony_ci * @tc.steps: step3. write event to the file. 1567405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 1577405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 1587405867cSopenharmony_ci */ 1597405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 1607405867cSopenharmony_ci int8_t num1 = 1; 1617405867cSopenharmony_ci OH_HiAppEvent_AddInt8Param(list, "int_key", num1); 1627405867cSopenharmony_ci int8_t nums1[] = {1, INT8_MIN, INT8_MAX}; 1637405867cSopenharmony_ci OH_HiAppEvent_AddInt8ArrayParam(list, "int8_arr_key", nums1, sizeof(nums1) / sizeof(nums1[0])); 1647405867cSopenharmony_ci int16_t num2 = 1; 1657405867cSopenharmony_ci OH_HiAppEvent_AddInt16Param(list, "int16_key", num2); 1667405867cSopenharmony_ci int16_t nums2[] = {1, INT16_MAX, INT16_MIN}; 1677405867cSopenharmony_ci OH_HiAppEvent_AddInt16ArrayParam(list, "int16_key", nums2, sizeof(nums2) / sizeof(nums2[0])); 1687405867cSopenharmony_ci 1697405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, BEHAVIOR, list); 1707405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 1717405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_DUPLICATE_PARAM); 1727405867cSopenharmony_ci} 1737405867cSopenharmony_ci 1747405867cSopenharmony_ci/** 1757405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest003 1767405867cSopenharmony_ci * @tc.desc: check the logging function when the input value is nullptr. 1777405867cSopenharmony_ci * @tc.type: FUNC 1787405867cSopenharmony_ci * @tc.require: AR000GIKMA 1797405867cSopenharmony_ci */ 1807405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest003, TestSize.Level0) 1817405867cSopenharmony_ci{ 1827405867cSopenharmony_ci /** 1837405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 1847405867cSopenharmony_ci * @tc.steps: step2. add params with the nullptr value to the ParamList. 1857405867cSopenharmony_ci * @tc.steps: step3. write event to the file. 1867405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 1877405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 1887405867cSopenharmony_ci */ 1897405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, FAULT, nullptr); 1907405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 1917405867cSopenharmony_ci 1927405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 1937405867cSopenharmony_ci bool boolean = true; 1947405867cSopenharmony_ci OH_HiAppEvent_AddBoolParam(list, nullptr, boolean); 1957405867cSopenharmony_ci OH_HiAppEvent_AddBoolArrayParam(list, "bool_arr_key", nullptr, 0); 1967405867cSopenharmony_ci int8_t num1 = 1; 1977405867cSopenharmony_ci OH_HiAppEvent_AddInt8Param(list, nullptr, num1); 1987405867cSopenharmony_ci OH_HiAppEvent_AddInt8ArrayParam(list, "int8_arr_key", nullptr, 0); 1997405867cSopenharmony_ci int16_t num2 = 1; 2007405867cSopenharmony_ci OH_HiAppEvent_AddInt16Param(list, nullptr, num2); 2017405867cSopenharmony_ci OH_HiAppEvent_AddInt16ArrayParam(list, "int16_arr_key", nullptr, 1); 2027405867cSopenharmony_ci int32_t num3 = 1; 2037405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, nullptr, num3); 2047405867cSopenharmony_ci OH_HiAppEvent_AddInt32ArrayParam(list, "int32_arr_key", nullptr, 2); 2057405867cSopenharmony_ci int64_t num4 = 1; 2067405867cSopenharmony_ci OH_HiAppEvent_AddInt64Param(list, nullptr, num4); 2077405867cSopenharmony_ci OH_HiAppEvent_AddInt64ArrayParam(list, "int64_arr_key", nullptr, 3); 2087405867cSopenharmony_ci float num5 = 465.1234; 2097405867cSopenharmony_ci OH_HiAppEvent_AddFloatParam(list, nullptr, num5); 2107405867cSopenharmony_ci OH_HiAppEvent_AddFloatArrayParam(list, "float_arr_key", nullptr, -1); 2117405867cSopenharmony_ci double num6 = 465.1234; 2127405867cSopenharmony_ci OH_HiAppEvent_AddDoubleParam(list, nullptr, num6); 2137405867cSopenharmony_ci OH_HiAppEvent_AddDoubleArrayParam(list, "double_arr_key", nullptr, 0); 2147405867cSopenharmony_ci char str1[] = "hello"; 2157405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, nullptr, str1); 2167405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, nullptr, nullptr); 2177405867cSopenharmony_ci OH_HiAppEvent_AddStringArrayParam(list, "str_arr_key", nullptr, 0); 2187405867cSopenharmony_ci char* strs[] = {str1, nullptr}; 2197405867cSopenharmony_ci OH_HiAppEvent_AddStringArrayParam(list, "str_arr_null_key", strs, sizeof(strs) / sizeof(strs[0])); 2207405867cSopenharmony_ci 2217405867cSopenharmony_ci res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, STATISTIC, list); 2227405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 2237405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 2247405867cSopenharmony_ci} 2257405867cSopenharmony_ci 2267405867cSopenharmony_ci/** 2277405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest004 2287405867cSopenharmony_ci * @tc.desc: check the verification function of event logging. 2297405867cSopenharmony_ci * @tc.type: FUNC 2307405867cSopenharmony_ci * @tc.require: AR000GIKMA 2317405867cSopenharmony_ci */ 2327405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest004, TestSize.Level0) 2337405867cSopenharmony_ci{ 2347405867cSopenharmony_ci /** 2357405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 2367405867cSopenharmony_ci * @tc.steps: step2. add params with the invalid name to the ParamList. 2377405867cSopenharmony_ci * @tc.steps: step3. write event to the file. 2387405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 2397405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 2407405867cSopenharmony_ci */ 2417405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 2427405867cSopenharmony_ci char key1[] = "**"; 2437405867cSopenharmony_ci int8_t num1 = 1; 2447405867cSopenharmony_ci OH_HiAppEvent_AddInt8Param(list, key1, num1); 2457405867cSopenharmony_ci char key2[] = "HH22"; 2467405867cSopenharmony_ci int16_t num2 = 1; 2477405867cSopenharmony_ci OH_HiAppEvent_AddInt16Param(list, key2, num2); 2487405867cSopenharmony_ci char key3[] = "aa_"; 2497405867cSopenharmony_ci int32_t num3 = 1; 2507405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, key3, num3); 2517405867cSopenharmony_ci char key4[] = ""; 2527405867cSopenharmony_ci int64_t num4 = 1; 2537405867cSopenharmony_ci OH_HiAppEvent_AddInt64Param(list, key4, num4); 2547405867cSopenharmony_ci 2557405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, SECURITY, list); 2567405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 2577405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_PARAM_NAME); 2587405867cSopenharmony_ci} 2597405867cSopenharmony_ci 2607405867cSopenharmony_ci/** 2617405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest005 2627405867cSopenharmony_ci * @tc.desc: check the verification function of event logging. 2637405867cSopenharmony_ci * @tc.type: FUNC 2647405867cSopenharmony_ci * @tc.require: AR000GIKMA 2657405867cSopenharmony_ci */ 2667405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest005, TestSize.Level0) 2677405867cSopenharmony_ci{ 2687405867cSopenharmony_ci /** 2697405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 2707405867cSopenharmony_ci * @tc.steps: step2. add params with too long string length to the ParamList. 2717405867cSopenharmony_ci * @tc.steps: step3. write event to the file. 2727405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 2737405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 2747405867cSopenharmony_ci */ 2757405867cSopenharmony_ci int maxStrLen = 8 * 1024; 2767405867cSopenharmony_ci std::string longStr(maxStrLen, 'a'); 2777405867cSopenharmony_ci std::string longInvalidStr(maxStrLen + 1, 'a'); 2787405867cSopenharmony_ci const char* strs[] = {"hello", longStr.c_str()}; 2797405867cSopenharmony_ci const char* strIns[] = {"hello", longInvalidStr.c_str()}; 2807405867cSopenharmony_ci 2817405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 2827405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, "long_s_key", longStr.c_str()); 2837405867cSopenharmony_ci OH_HiAppEvent_AddStringArrayParam(list, "long_s_a_key", strs, sizeof(strs) / sizeof(strs[0])); 2847405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, "long_s_i_key", longInvalidStr.c_str()); 2857405867cSopenharmony_ci OH_HiAppEvent_AddStringArrayParam(list, "long_s_a_i_key", strIns, sizeof(strIns) / sizeof(strIns[0])); 2867405867cSopenharmony_ci 2877405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, SECURITY, list); 2887405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 2897405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_PARAM_VALUE_LENGTH); 2907405867cSopenharmony_ci} 2917405867cSopenharmony_ci 2927405867cSopenharmony_ci/** 2937405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest006 2947405867cSopenharmony_ci * @tc.desc: check the verification function of event logging. 2957405867cSopenharmony_ci * @tc.type: FUNC 2967405867cSopenharmony_ci * @tc.require: AR000GIKMA 2977405867cSopenharmony_ci */ 2987405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest006, TestSize.Level0) 2997405867cSopenharmony_ci{ 3007405867cSopenharmony_ci /** 3017405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 3027405867cSopenharmony_ci * @tc.steps: step2. add too many params to the ParamList. 3037405867cSopenharmony_ci * @tc.steps: step3. write event to the file. 3047405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 3057405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 3067405867cSopenharmony_ci */ 3077405867cSopenharmony_ci // max len is 32 3087405867cSopenharmony_ci int len = 33; 3097405867cSopenharmony_ci std::vector<std::string> keys(len); 3107405867cSopenharmony_ci std::vector<std::string> values(len); 3117405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 3127405867cSopenharmony_ci for (int i = 0; i < len; i++) { 3137405867cSopenharmony_ci keys[i] = "key" + std::to_string(i); 3147405867cSopenharmony_ci values[i] = "value" + std::to_string(i); 3157405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str()); 3167405867cSopenharmony_ci } 3177405867cSopenharmony_ci 3187405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, SECURITY, list); 3197405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 3207405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_PARAM_NUM); 3217405867cSopenharmony_ci} 3227405867cSopenharmony_ci 3237405867cSopenharmony_ci/** 3247405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest007 3257405867cSopenharmony_ci * @tc.desc: check the verification function of event logging. 3267405867cSopenharmony_ci * @tc.type: FUNC 3277405867cSopenharmony_ci * @tc.require: AR000GIKMA 3287405867cSopenharmony_ci */ 3297405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest007, TestSize.Level0) 3307405867cSopenharmony_ci{ 3317405867cSopenharmony_ci /** 3327405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 3337405867cSopenharmony_ci * @tc.steps: step2. add params to the ParamList. 3347405867cSopenharmony_ci * @tc.steps: step3. write event with invalid event name to the file. 3357405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 3367405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 3377405867cSopenharmony_ci */ 3387405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 3397405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, "int_key", 1); 3407405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, "verify_**", SECURITY, list); 3417405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 3427405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_NAME); 3437405867cSopenharmony_ci 3447405867cSopenharmony_ci list = OH_HiAppEvent_CreateParamList(); 3457405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, "int_key", 2); 3467405867cSopenharmony_ci res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, "verify_TEST_", SECURITY, list); 3477405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 3487405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_NAME); 3497405867cSopenharmony_ci 3507405867cSopenharmony_ci list = OH_HiAppEvent_CreateParamList(); 3517405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, "int_key", 3); 3527405867cSopenharmony_ci res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, "", SECURITY, list); 3537405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 3547405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_NAME); 3557405867cSopenharmony_ci} 3567405867cSopenharmony_ci 3577405867cSopenharmony_ci/** 3587405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest008 3597405867cSopenharmony_ci * @tc.desc: check the verification function of event logging. 3607405867cSopenharmony_ci * @tc.type: FUNC 3617405867cSopenharmony_ci * @tc.require: AR000GIKMA 3627405867cSopenharmony_ci */ 3637405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest008, TestSize.Level0) 3647405867cSopenharmony_ci{ 3657405867cSopenharmony_ci /** 3667405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 3677405867cSopenharmony_ci * @tc.steps: step2. add params to the ParamList. 3687405867cSopenharmony_ci * @tc.steps: step3. write event with nullptr event name to the file. 3697405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 3707405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 3717405867cSopenharmony_ci */ 3727405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 3737405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, "int_key", 1); 3747405867cSopenharmony_ci 3757405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, nullptr, SECURITY, list); 3767405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 3777405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_NAME); 3787405867cSopenharmony_ci} 3797405867cSopenharmony_ci 3807405867cSopenharmony_ci/** 3817405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest009 3827405867cSopenharmony_ci * @tc.desc: check the verification function of event logging. 3837405867cSopenharmony_ci * @tc.type: FUNC 3847405867cSopenharmony_ci * @tc.require: AR000GIKMA 3857405867cSopenharmony_ci */ 3867405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest009, TestSize.Level0) 3877405867cSopenharmony_ci{ 3887405867cSopenharmony_ci /** 3897405867cSopenharmony_ci * @tc.steps: step1. disable the logging function. 3907405867cSopenharmony_ci * @tc.steps: step2. create a ParamList pointer. 3917405867cSopenharmony_ci * @tc.steps: step3. add params to the ParamList. 3927405867cSopenharmony_ci * @tc.steps: step4. write event to the file. 3937405867cSopenharmony_ci * @tc.steps: step5. check the result of logging. 3947405867cSopenharmony_ci * @tc.steps: step6. destroy the ParamList pointer. 3957405867cSopenharmony_ci */ 3967405867cSopenharmony_ci OH_HiAppEvent_Configure(DISABLE, "true"); 3977405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 3987405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, "int_key", 1); 3997405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, SECURITY, list); 4007405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 4017405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_HIAPPEVENT_DISABLE); 4027405867cSopenharmony_ci 4037405867cSopenharmony_ci OH_HiAppEvent_Configure(DISABLE, "false"); 4047405867cSopenharmony_ci list = OH_HiAppEvent_CreateParamList(); 4057405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, "str_key", "test"); 4067405867cSopenharmony_ci res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, SECURITY, list); 4077405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 4087405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 4097405867cSopenharmony_ci} 4107405867cSopenharmony_ci 4117405867cSopenharmony_ci/** 4127405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest010 4137405867cSopenharmony_ci * @tc.desc: check the configuration function of event logging. 4147405867cSopenharmony_ci * @tc.type: FUNC 4157405867cSopenharmony_ci * @tc.require: AR000GIKMA 4167405867cSopenharmony_ci */ 4177405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest010, TestSize.Level0) 4187405867cSopenharmony_ci{ 4197405867cSopenharmony_ci /** 4207405867cSopenharmony_ci * @tc.steps: step1. config with invalid params. 4217405867cSopenharmony_ci * @tc.steps: step2. check the result of config. 4227405867cSopenharmony_ci */ 4237405867cSopenharmony_ci bool res = OH_HiAppEvent_Configure(nullptr, nullptr); 4247405867cSopenharmony_ci ASSERT_FALSE(res); 4257405867cSopenharmony_ci 4267405867cSopenharmony_ci res = OH_HiAppEvent_Configure("key", "true"); 4277405867cSopenharmony_ci ASSERT_FALSE(res); 4287405867cSopenharmony_ci 4297405867cSopenharmony_ci res = OH_HiAppEvent_Configure(DISABLE, "xxx"); 4307405867cSopenharmony_ci ASSERT_FALSE(res); 4317405867cSopenharmony_ci 4327405867cSopenharmony_ci res = OH_HiAppEvent_Configure(MAX_STORAGE, "xxx"); 4337405867cSopenharmony_ci ASSERT_FALSE(res); 4347405867cSopenharmony_ci 4357405867cSopenharmony_ci res = OH_HiAppEvent_Configure("", "100M"); 4367405867cSopenharmony_ci ASSERT_FALSE(res); 4377405867cSopenharmony_ci} 4387405867cSopenharmony_ci 4397405867cSopenharmony_ci/** 4407405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest011 4417405867cSopenharmony_ci * @tc.desc: check the configuration function of event logging. 4427405867cSopenharmony_ci * @tc.type: FUNC 4437405867cSopenharmony_ci * @tc.require: AR000GIKMA 4447405867cSopenharmony_ci */ 4457405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest011, TestSize.Level0) 4467405867cSopenharmony_ci{ 4477405867cSopenharmony_ci /** 4487405867cSopenharmony_ci * @tc.steps: step1. config the storage directory quota of the logging function. 4497405867cSopenharmony_ci * @tc.steps: step2. check the result of config. 4507405867cSopenharmony_ci * @tc.steps: step3. write event to the file. 4517405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 4527405867cSopenharmony_ci */ 4537405867cSopenharmony_ci bool res = OH_HiAppEvent_Configure(MAX_STORAGE, "1k"); 4547405867cSopenharmony_ci ASSERT_TRUE(res); 4557405867cSopenharmony_ci 4567405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 4577405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, "int_key", 1); 4587405867cSopenharmony_ci int result = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, SECURITY, list); 4597405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 4607405867cSopenharmony_ci ASSERT_EQ(result, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 4617405867cSopenharmony_ci 4627405867cSopenharmony_ci res = OH_HiAppEvent_Configure(MAX_STORAGE, "100M"); 4637405867cSopenharmony_ci ASSERT_TRUE(res); 4647405867cSopenharmony_ci} 4657405867cSopenharmony_ci 4667405867cSopenharmony_ci/** 4677405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest012 4687405867cSopenharmony_ci * @tc.desc: check the event logging function with predefined events. 4697405867cSopenharmony_ci * @tc.type: FUNC 4707405867cSopenharmony_ci * @tc.require: AR000GIKMA 4717405867cSopenharmony_ci */ 4727405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest012, TestSize.Level0) 4737405867cSopenharmony_ci{ 4747405867cSopenharmony_ci /** 4757405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 4767405867cSopenharmony_ci * @tc.steps: step2. add params with predefined param name to the ParamList. 4777405867cSopenharmony_ci * @tc.steps: step3. write event with predefined event name to the file. 4787405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 4797405867cSopenharmony_ci * @tc.steps: step5. destroy the ParamList pointer. 4807405867cSopenharmony_ci */ 4817405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 4827405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, PARAM_USER_ID, 123); 4837405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, EVENT_USER_LOGIN, BEHAVIOR, list); 4847405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 4857405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 4867405867cSopenharmony_ci 4877405867cSopenharmony_ci list = OH_HiAppEvent_CreateParamList(); 4887405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, PARAM_USER_ID, "123456"); 4897405867cSopenharmony_ci res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, EVENT_USER_LOGOUT, SECURITY, list); 4907405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 4917405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 4927405867cSopenharmony_ci 4937405867cSopenharmony_ci list = OH_HiAppEvent_CreateParamList(); 4947405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, PARAM_DISTRIBUTED_SERVICE_NAME, "hiview"); 4957405867cSopenharmony_ci OH_HiAppEvent_AddStringParam(list, PARAM_DISTRIBUTED_SERVICE_INSTANCE_ID, "123"); 4967405867cSopenharmony_ci res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, EVENT_DISTRIBUTED_SERVICE_START, SECURITY, list); 4977405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 4987405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 4997405867cSopenharmony_ci} 5007405867cSopenharmony_ci 5017405867cSopenharmony_ci/** 5027405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest013 5037405867cSopenharmony_ci * @tc.desc: check the local file. 5047405867cSopenharmony_ci * @tc.type: FUNC 5057405867cSopenharmony_ci * @tc.require: AR000GIKMA 5067405867cSopenharmony_ci */ 5077405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest013, TestSize.Level0) 5087405867cSopenharmony_ci{ 5097405867cSopenharmony_ci /** 5107405867cSopenharmony_ci * @tc.steps: step1. create a ParamList pointer. 5117405867cSopenharmony_ci * @tc.steps: step2. add params to the ParamList. 5127405867cSopenharmony_ci * @tc.steps: step3. write event to the file. 5137405867cSopenharmony_ci * @tc.steps: step4. check the result of logging. 5147405867cSopenharmony_ci * @tc.steps: step5. check the file. 5157405867cSopenharmony_ci */ 5167405867cSopenharmony_ci ParamList list = OH_HiAppEvent_CreateParamList(); 5177405867cSopenharmony_ci OH_HiAppEvent_AddInt32Param(list, "int_key", 123); 5187405867cSopenharmony_ci int res = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, BEHAVIOR, list); 5197405867cSopenharmony_ci OH_HiAppEvent_DestroyParamList(list); 5207405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 5217405867cSopenharmony_ci 5227405867cSopenharmony_ci sleep(1); // wait 1s for WriteEvent complete 5237405867cSopenharmony_ci std::string filePath = TEST_STORAGE_PATH + GetStorageFilePath(); 5247405867cSopenharmony_ci ASSERT_EQ(access(filePath.c_str(), F_OK), 0); 5257405867cSopenharmony_ci} 5267405867cSopenharmony_ci 5277405867cSopenharmony_ci/** 5287405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest014 5297405867cSopenharmony_ci * @tc.desc: check the domain verification function of event logging. 5307405867cSopenharmony_ci * @tc.type: FUNC 5317405867cSopenharmony_ci * @tc.require: issueI8OY2U 5327405867cSopenharmony_ci */ 5337405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest014, TestSize.Level0) 5347405867cSopenharmony_ci{ 5357405867cSopenharmony_ci int res = OH_HiAppEvent_Write(nullptr, TEST_EVENT_NAME, SECURITY, nullptr); 5367405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_DOMAIN); 5377405867cSopenharmony_ci 5387405867cSopenharmony_ci res = OH_HiAppEvent_Write("", TEST_EVENT_NAME, SECURITY, nullptr); 5397405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_DOMAIN); 5407405867cSopenharmony_ci 5417405867cSopenharmony_ci constexpr size_t limitLen = 32; 5427405867cSopenharmony_ci res = OH_HiAppEvent_Write(std::string(limitLen, 'a').c_str(), TEST_EVENT_NAME, SECURITY, nullptr); 5437405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 5447405867cSopenharmony_ci res = OH_HiAppEvent_Write(std::string(limitLen + 1, 'a').c_str(), TEST_EVENT_NAME, SECURITY, nullptr); 5457405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_DOMAIN); 5467405867cSopenharmony_ci 5477405867cSopenharmony_ci std::string invalidDomain = std::string(limitLen - 1, 'a') + "_"; 5487405867cSopenharmony_ci res = OH_HiAppEvent_Write(invalidDomain.c_str(), TEST_EVENT_NAME, SECURITY, nullptr); 5497405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_DOMAIN); 5507405867cSopenharmony_ci 5517405867cSopenharmony_ci res = OH_HiAppEvent_Write("AAAaaa", TEST_EVENT_NAME, SECURITY, nullptr); 5527405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 5537405867cSopenharmony_ci 5547405867cSopenharmony_ci res = OH_HiAppEvent_Write("abc***", TEST_EVENT_NAME, SECURITY, nullptr); 5557405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_DOMAIN); 5567405867cSopenharmony_ci 5577405867cSopenharmony_ci res = OH_HiAppEvent_Write("domain_", TEST_EVENT_NAME, SECURITY, nullptr); 5587405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::ERROR_INVALID_EVENT_DOMAIN); 5597405867cSopenharmony_ci 5607405867cSopenharmony_ci res = OH_HiAppEvent_Write("a", TEST_EVENT_NAME, SECURITY, nullptr); 5617405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 5627405867cSopenharmony_ci 5637405867cSopenharmony_ci res = OH_HiAppEvent_Write("a1", TEST_EVENT_NAME, SECURITY, nullptr); 5647405867cSopenharmony_ci ASSERT_EQ(res, ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); 5657405867cSopenharmony_ci} 5667405867cSopenharmony_ci 5677405867cSopenharmony_ci/** 5687405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest015 5697405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_CreateWatcher. 5707405867cSopenharmony_ci * @tc.type: FUNC 5717405867cSopenharmony_ci * @tc.require: issueI8OY2U 5727405867cSopenharmony_ci */ 5737405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest015, TestSize.Level0) 5747405867cSopenharmony_ci{ 5757405867cSopenharmony_ci ASSERT_TRUE(OH_HiAppEvent_CreateWatcher(nullptr) == nullptr); 5767405867cSopenharmony_ci g_onReceiveWatcher = OH_HiAppEvent_CreateWatcher("test_onReceiver_watcher"); 5777405867cSopenharmony_ci ASSERT_TRUE(g_onReceiveWatcher != nullptr); 5787405867cSopenharmony_ci g_onTriggerWatcher = OH_HiAppEvent_CreateWatcher("test_onTrigger_watcher"); 5797405867cSopenharmony_ci ASSERT_TRUE(g_onTriggerWatcher != nullptr); 5807405867cSopenharmony_ci} 5817405867cSopenharmony_ci 5827405867cSopenharmony_ci/** 5837405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest016 5847405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_SetAppEventFilter. 5857405867cSopenharmony_ci * @tc.type: FUNC 5867405867cSopenharmony_ci * @tc.require: issueI8OY2U 5877405867cSopenharmony_ci */ 5887405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest016, TestSize.Level0) 5897405867cSopenharmony_ci{ 5907405867cSopenharmony_ci const char* filterNames[] = {TEST_EVENT_NAME}; 5917405867cSopenharmony_ci const char* filterNamesWithNullptr[] = {nullptr}; 5927405867cSopenharmony_ci constexpr int namsLen = 1; 5937405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetAppEventFilter(nullptr, TEST_DOMAIN_NAME, 0, filterNames, namsLen), 5947405867cSopenharmony_ci ErrorCode::ERROR_INVALID_WATCHER); 5957405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetAppEventFilter(g_onReceiveWatcher, nullptr, 0, filterNames, namsLen), 5967405867cSopenharmony_ci ErrorCode::ERROR_INVALID_EVENT_DOMAIN); 5977405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetAppEventFilter(g_onReceiveWatcher, TEST_DOMAIN_NAME, 0, nullptr, namsLen), 5987405867cSopenharmony_ci ErrorCode::ERROR_INVALID_EVENT_NAME); 5997405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetAppEventFilter(g_onReceiveWatcher, TEST_DOMAIN_NAME, 0, filterNamesWithNullptr, namsLen), 6007405867cSopenharmony_ci ErrorCode::ERROR_INVALID_EVENT_NAME); 6017405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetAppEventFilter(g_onReceiveWatcher, TEST_DOMAIN_NAME, 0, filterNames, namsLen), 0); 6027405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetAppEventFilter(g_onTriggerWatcher, TEST_DOMAIN_NAME, 0, filterNames, namsLen), 0); 6037405867cSopenharmony_ci} 6047405867cSopenharmony_ci 6057405867cSopenharmony_ci/** 6067405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest017 6077405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_SetWatcherOnReceiver. 6087405867cSopenharmony_ci * @tc.type: FUNC 6097405867cSopenharmony_ci * @tc.require: issueI8OY2U 6107405867cSopenharmony_ci */ 6117405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest017, TestSize.Level0) 6127405867cSopenharmony_ci{ 6137405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetWatcherOnReceive(nullptr, OnReceive), ErrorCode::ERROR_INVALID_WATCHER); 6147405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetWatcherOnReceive(g_onReceiveWatcher, OnReceive), 0); 6157405867cSopenharmony_ci} 6167405867cSopenharmony_ci 6177405867cSopenharmony_ci/** 6187405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest018 6197405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_SetTriggerCondition. 6207405867cSopenharmony_ci * @tc.type: FUNC 6217405867cSopenharmony_ci * @tc.require: issueI8OY2U 6227405867cSopenharmony_ci */ 6237405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest018, TestSize.Level0) 6247405867cSopenharmony_ci{ 6257405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetTriggerCondition(nullptr, TEST_EVENT_NUM, 0, 0), ErrorCode::ERROR_INVALID_WATCHER); 6267405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetTriggerCondition(g_onTriggerWatcher, TEST_EVENT_NUM, 0, 0), 0); 6277405867cSopenharmony_ci} 6287405867cSopenharmony_ci 6297405867cSopenharmony_ci/** 6307405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest019 6317405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_SetWatcherOnTrigger. 6327405867cSopenharmony_ci * @tc.type: FUNC 6337405867cSopenharmony_ci * @tc.require: issueI8OY2U 6347405867cSopenharmony_ci */ 6357405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest019, TestSize.Level0) 6367405867cSopenharmony_ci{ 6377405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetWatcherOnTrigger(nullptr, OnTrigger), ErrorCode::ERROR_INVALID_WATCHER); 6387405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_SetWatcherOnTrigger(g_onTriggerWatcher, OnTrigger), 0); 6397405867cSopenharmony_ci} 6407405867cSopenharmony_ci 6417405867cSopenharmony_ci/** 6427405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest020 6437405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_AddWatcher. 6447405867cSopenharmony_ci * @tc.type: FUNC 6457405867cSopenharmony_ci * @tc.require: issueI8OY2U 6467405867cSopenharmony_ci */ 6477405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest020, TestSize.Level0) 6487405867cSopenharmony_ci{ 6497405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_AddWatcher(nullptr), ErrorCode::ERROR_INVALID_WATCHER); 6507405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_AddWatcher(g_onTriggerWatcher), 0); 6517405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_AddWatcher(g_onReceiveWatcher), 0); 6527405867cSopenharmony_ci for (int i = 0; i < TEST_EVENT_NUM; ++i) { 6537405867cSopenharmony_ci WriteEvent(); 6547405867cSopenharmony_ci } 6557405867cSopenharmony_ci} 6567405867cSopenharmony_ci 6577405867cSopenharmony_ci/** 6587405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest021 6597405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_TakeWatcherData. 6607405867cSopenharmony_ci * @tc.type: FUNC 6617405867cSopenharmony_ci * @tc.require: issueI8OY2U 6627405867cSopenharmony_ci */ 6637405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest021, TestSize.Level0) 6647405867cSopenharmony_ci{ 6657405867cSopenharmony_ci constexpr uint32_t takeNum = 10; 6667405867cSopenharmony_ci sleep(1); // wait 1s for WriteEvent complete 6677405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_TakeWatcherData(nullptr, takeNum, OnTake), ErrorCode::ERROR_INVALID_WATCHER); 6687405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_TakeWatcherData(g_onTriggerWatcher, takeNum, OnTake), 0); 6697405867cSopenharmony_ci} 6707405867cSopenharmony_ci 6717405867cSopenharmony_ci/** 6727405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest022 6737405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_ClearData. 6747405867cSopenharmony_ci * @tc.type: FUNC 6757405867cSopenharmony_ci * @tc.require: issueI8OY2U 6767405867cSopenharmony_ci */ 6777405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest022, TestSize.Level0) 6787405867cSopenharmony_ci{ 6797405867cSopenharmony_ci OH_HiAppEvent_ClearData(); 6807405867cSopenharmony_ci ASSERT_EQ(HiAppEvent::UserInfo::GetInstance().GetUserIdVersion(), 0); 6817405867cSopenharmony_ci ASSERT_EQ(HiAppEvent::UserInfo::GetInstance().GetUserPropertyVersion(), 0); 6827405867cSopenharmony_ci} 6837405867cSopenharmony_ci 6847405867cSopenharmony_ci/** 6857405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest023 6867405867cSopenharmony_ci * @tc.desc: check the function of OH_HiAppEvent_RemoveWatcher. 6877405867cSopenharmony_ci * @tc.type: FUNC 6887405867cSopenharmony_ci * @tc.require: issueI8OY2U 6897405867cSopenharmony_ci */ 6907405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest023, TestSize.Level0) 6917405867cSopenharmony_ci{ 6927405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_RemoveWatcher(g_onTriggerWatcher), 0); 6937405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_RemoveWatcher(g_onTriggerWatcher), ErrorCode::ERROR_WATCHER_NOT_ADDED); 6947405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_RemoveWatcher(g_onReceiveWatcher), 0); 6957405867cSopenharmony_ci ASSERT_EQ(OH_HiAppEvent_RemoveWatcher(g_onReceiveWatcher), ErrorCode::ERROR_WATCHER_NOT_ADDED); 6967405867cSopenharmony_ci OH_HiAppEvent_DestroyWatcher(g_onTriggerWatcher); 6977405867cSopenharmony_ci g_onTriggerWatcher = nullptr; 6987405867cSopenharmony_ci OH_HiAppEvent_DestroyWatcher(g_onReceiveWatcher); 6997405867cSopenharmony_ci g_onReceiveWatcher = nullptr; 7007405867cSopenharmony_ci} 7017405867cSopenharmony_ci 7027405867cSopenharmony_ci/** 7037405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest024 7047405867cSopenharmony_ci * @tc.desc: check ndk interface of AddProcessor. 7057405867cSopenharmony_ci * @tc.type: FUNC 7067405867cSopenharmony_ci */ 7077405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest024, TestSize.Level0) 7087405867cSopenharmony_ci{ 7097405867cSopenharmony_ci setuid(0); // 0 means root uid 7107405867cSopenharmony_ci ASSERT_EQ(CreateProcessor(TEST_PROCESSOR_NAME), nullptr); 7117405867cSopenharmony_ci ASSERT_EQ(SetReportRoute(nullptr, nullptr, nullptr), ErrorCode::ERROR_NOT_APP); 7127405867cSopenharmony_ci ASSERT_EQ(SetReportPolicy(nullptr, 0, 0, false, false), ErrorCode::ERROR_NOT_APP); 7137405867cSopenharmony_ci ASSERT_EQ(SetReportEvent(nullptr, nullptr, nullptr, false), ErrorCode::ERROR_NOT_APP); 7147405867cSopenharmony_ci ASSERT_EQ(SetCustomConfig(nullptr, nullptr, nullptr), ErrorCode::ERROR_NOT_APP); 7157405867cSopenharmony_ci ASSERT_EQ(SetConfigId(nullptr, 0), ErrorCode::ERROR_NOT_APP); 7167405867cSopenharmony_ci ASSERT_EQ(SetReportUserId(nullptr, nullptr, 0), ErrorCode::ERROR_NOT_APP); 7177405867cSopenharmony_ci ASSERT_EQ(SetReportUserProperty(nullptr, nullptr, 0), ErrorCode::ERROR_NOT_APP); 7187405867cSopenharmony_ci ASSERT_EQ(AddProcessor(nullptr), ErrorCode::ERROR_NOT_APP); 7197405867cSopenharmony_ci DestoryProcessor(nullptr); 7207405867cSopenharmony_ci ASSERT_EQ(RemoveProcessor(0), ErrorCode::ERROR_NOT_APP); 7217405867cSopenharmony_ci 7227405867cSopenharmony_ci // set app uid 7237405867cSopenharmony_ci setuid(TEST_UID); 7247405867cSopenharmony_ci 7257405867cSopenharmony_ci ASSERT_EQ(CreateProcessor(nullptr), nullptr); 7267405867cSopenharmony_ci ASSERT_EQ(SetReportRoute(nullptr, nullptr, nullptr), ErrorCode::ERROR_INVALID_PROCESSOR); 7277405867cSopenharmony_ci ASSERT_EQ(SetReportPolicy(nullptr, 0, 0, false, false), ErrorCode::ERROR_INVALID_PROCESSOR); 7287405867cSopenharmony_ci ASSERT_EQ(SetReportEvent(nullptr, nullptr, nullptr, false), ErrorCode::ERROR_INVALID_PROCESSOR); 7297405867cSopenharmony_ci ASSERT_EQ(SetCustomConfig(nullptr, nullptr, nullptr), ErrorCode::ERROR_INVALID_PROCESSOR); 7307405867cSopenharmony_ci ASSERT_EQ(SetConfigId(nullptr, 0), ErrorCode::ERROR_INVALID_PROCESSOR); 7317405867cSopenharmony_ci ASSERT_EQ(SetReportUserId(nullptr, nullptr, 0), ErrorCode::ERROR_INVALID_PROCESSOR); 7327405867cSopenharmony_ci ASSERT_EQ(SetReportUserProperty(nullptr, nullptr, 0), ErrorCode::ERROR_INVALID_PROCESSOR); 7337405867cSopenharmony_ci ASSERT_EQ(AddProcessor(nullptr), ErrorCode::ERROR_INVALID_PROCESSOR); 7347405867cSopenharmony_ci DestoryProcessor(nullptr); 7357405867cSopenharmony_ci ASSERT_EQ(RemoveProcessor(0), ErrorCode::ERROR_PROCESSOR_NOT_ADDED); 7367405867cSopenharmony_ci} 7377405867cSopenharmony_ci 7387405867cSopenharmony_ci/** 7397405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest025 7407405867cSopenharmony_ci * @tc.desc: check ndk interface of AddProcessor. 7417405867cSopenharmony_ci * @tc.type: FUNC 7427405867cSopenharmony_ci */ 7437405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest025, TestSize.Level0) 7447405867cSopenharmony_ci{ 7457405867cSopenharmony_ci ASSERT_EQ(CreateProcessor(""), nullptr); 7467405867cSopenharmony_ci auto processor = CreateProcessor(TEST_PROCESSOR_NAME); 7477405867cSopenharmony_ci ASSERT_TRUE(processor != nullptr); 7487405867cSopenharmony_ci ASSERT_EQ(SetReportRoute(processor, nullptr, nullptr), ErrorCode::ERROR_INVALID_PARAM_VALUE); 7497405867cSopenharmony_ci ASSERT_EQ(SetReportRoute(processor, "", ""), 0); 7507405867cSopenharmony_ci ASSERT_EQ(SetReportPolicy(processor, -1, 0, false, false), ErrorCode::ERROR_INVALID_PARAM_VALUE); 7517405867cSopenharmony_ci ASSERT_EQ(SetReportEvent(processor, nullptr, nullptr, false), ErrorCode::ERROR_INVALID_PARAM_VALUE); 7527405867cSopenharmony_ci ASSERT_EQ(SetCustomConfig(processor, nullptr, nullptr), ErrorCode::ERROR_INVALID_PARAM_VALUE); 7537405867cSopenharmony_ci ASSERT_EQ(SetCustomConfig(processor, "", ""), ErrorCode::ERROR_INVALID_PARAM_VALUE_LENGTH); 7547405867cSopenharmony_ci ASSERT_EQ(SetConfigId(processor, -1), ErrorCode::ERROR_INVALID_PARAM_VALUE); 7557405867cSopenharmony_ci ASSERT_EQ(SetReportUserId(processor, nullptr, 0), ErrorCode::ERROR_INVALID_PARAM_VALUE); 7567405867cSopenharmony_ci const char* userStrs[] = {"aaa", ""}; 7577405867cSopenharmony_ci ASSERT_EQ(SetReportUserId(processor, userStrs, 0), 0); 7587405867cSopenharmony_ci ASSERT_EQ(SetReportUserProperty(processor, nullptr, 0), ErrorCode::ERROR_INVALID_PARAM_VALUE); 7597405867cSopenharmony_ci ASSERT_EQ(SetReportUserProperty(processor, userStrs, 0), 0); 7607405867cSopenharmony_ci int seq = AddProcessor(processor); 7617405867cSopenharmony_ci ASSERT_GT(seq, 0); 7627405867cSopenharmony_ci DestoryProcessor(processor); 7637405867cSopenharmony_ci ASSERT_EQ(RemoveProcessor(seq), 0); 7647405867cSopenharmony_ci} 7657405867cSopenharmony_ci 7667405867cSopenharmony_ci/** 7677405867cSopenharmony_ci * @tc.name: HiAppEventNDKTest026 7687405867cSopenharmony_ci * @tc.desc: check ndk interface of AddProcessor. 7697405867cSopenharmony_ci * @tc.type: FUNC 7707405867cSopenharmony_ci */ 7717405867cSopenharmony_ciHWTEST_F(HiAppEventNativeTest, HiAppEventNDKTest026, TestSize.Level0) 7727405867cSopenharmony_ci{ 7737405867cSopenharmony_ci auto processor = CreateProcessor(TEST_PROCESSOR_NAME); 7747405867cSopenharmony_ci ASSERT_TRUE(processor != nullptr); 7757405867cSopenharmony_ci ASSERT_EQ(SetReportRoute(processor, "test_appid", "test_routeInfo"), 0); 7767405867cSopenharmony_ci ASSERT_EQ(SetReportPolicy(processor, 2, 2, false, false), 0); 7777405867cSopenharmony_ci ASSERT_EQ(SetReportEvent(processor, "test_domain", "test_name", false), 0); 7787405867cSopenharmony_ci ASSERT_EQ(SetCustomConfig(processor, "str_key", "str_value"), 0); 7797405867cSopenharmony_ci ASSERT_EQ(SetConfigId(processor, 1), 0); 7807405867cSopenharmony_ci const char* userIds[] = {"test_id"}; 7817405867cSopenharmony_ci ASSERT_EQ(SetReportUserId(processor, userIds, 1), 0); 7827405867cSopenharmony_ci const char* userProperties[] = {"test_property"}; 7837405867cSopenharmony_ci ASSERT_EQ(SetReportUserProperty(processor, userProperties, 1), 0); 7847405867cSopenharmony_ci int seq = AddProcessor(processor); 7857405867cSopenharmony_ci ASSERT_GT(seq, 0); 7867405867cSopenharmony_ci DestoryProcessor(processor); 7877405867cSopenharmony_ci ASSERT_EQ(RemoveProcessor(seq), 0); 7887405867cSopenharmony_ci}