diff --git a/hiviewdfx/BUILD.gn b/hiviewdfx/BUILD.gn index b7da56ec217312a073c5f4251621611253f13ae3..e97b2a689b5ff70a29f338f1d3de61764de45fd7 100644 --- a/hiviewdfx/BUILD.gn +++ b/hiviewdfx/BUILD.gn @@ -16,10 +16,12 @@ group("hiviewdfxtestacts") { if (is_standard_system) { deps = [ "bytracetest:ActsBytraceJsTest", + "hiappeventtest/hiappeventcpptest:HiAppEventCPPTest", "hiappeventtest/hiappeventjstest:ActsHiAppeventTest", "hicheckertest/hicheckerjstest:hicheckerjstest", "hidebugtest/hidebugtestjstest:ActsHiDebugTest", - "hilogjstest:ActsHilogJsTest", + "hilogtest/hilogjstest:ActsHilogJsTest", + "hilogtest/hilogndktest:hilogndktest", "hitracechainjstest:ActsHiTraceChainJsTest", "hitracechaintest:ActsHiTraceChainTest", "hiview/faultlogger/faultloggerjs:faultloggerjs_test", diff --git a/hiviewdfx/hiappeventtest/hiappeventcpptest/BUILD.gn b/hiviewdfx/hiappeventtest/hiappeventcpptest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1f5a0fee4593c968022c46a7d9b07a2e43a94110 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventcpptest/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +module_output_path = "hit/HiAppEventCPPTest" + +############################################################################### +config("hilogtest_config") { + visibility = [ ":*" ] + include_dirs = [ + "//utils/native/base/include/", + "../../utils/native", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//base/hiviewdfx/hiappevent/interfaces/native/kits/include/hiappevent", + "//base/hiviewdfx/hiappevent/frameworks/native/libhiappevent/include", + ] +} +ohos_moduletest_suite("HiAppEventCPPTest") { + module_out_path = module_output_path + sources = [ "HiAppEventCPPTest.cpp" ] + deps = [ + "../../utils/native:utilskit", + "//base/hiviewdfx/hiappevent/frameworks/native/libhiappevent:libhiappevent_base", + "//base/hiviewdfx/hiappevent/frameworks/native/ndk:hiappevent_ndk", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + configs = [ ":hilogtest_config" ] +} diff --git a/hiviewdfx/hiappeventtest/hiappeventcpptest/HiAppEventCPPTest.cpp b/hiviewdfx/hiappeventtest/hiappeventcpptest/HiAppEventCPPTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..791fe02ca49a9b8a78eb547bbd26915b2a5d2efa --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventcpptest/HiAppEventCPPTest.cpp @@ -0,0 +1,1190 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hiappevent.h" +#include "hiappevent_config.h" +#include "hilog/log.h" +#include "file_utils.h" + + +using namespace std; +using namespace testing; +using namespace testing::ext; +using namespace OHOS::HiviewDFX; + +namespace { + const char* TEST_DOMAIN_NAME = "test_domain"; + const char* TEST_EVENT_NAME = "test_event"; + string g_reDiRectTimeout = "5"; + string logPath = "/data/test/hiappevent/"; + string delelogPath = "/data/test/hiappevent/*"; +} + +class HiAppEventCPPTest : public testing::Test { +public: + void TearDown(); +}; + +void HiAppEventCPPTest::TearDown() +{ + std::cout << "TearDown" << std::endl; + std::vector cmdret; + string cmd = "rm -f " + delelogPath; + ExecCmdWithRet(cmd, cmdret); +} + +/** +* @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue +* is of the boolean type and the bool value is false. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0100 +* @author f00601390 +* @tc.desc The keyvalue is of the boolean type and the bool value is false. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0100, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0100 start" << endl; + bool result = false; + bool boolean = false; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddBoolParam(list, "bool_key", boolean); + EventType eventType = EventType::FAULT; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1", "\"bool_key\":false"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0100 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0100 end" << endl; +} + +/** +* @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue +* is of the boolean type and the bool value is true. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0200 +* @author f00601390 +* @tc.desc The keyvalue is of the boolean type and the bool value is false. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0200, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0200 start" << endl; + bool result = false; + bool boolean = true; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddBoolParam(list, "bool_key", boolean); + EventType eventType = EventType::FAULT; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1", "\"bool_key\":true"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0200 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0200 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the Boolean List Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0300 +* @author f00601390 +* @tc.desc The keyvalue is reported as a boolean list. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0300, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0300 start" << endl; + bool result = false; + bool booleans[] = {true, true}; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddBoolArrayParam(list, "bool_arr_key", booleans, sizeof(booleans) / sizeof(booleans[0])); + EventType eventType = EventType::FAULT; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1", "\"bool_arr_key\":[true,true]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0300 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0300 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the Boolean List Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0400 +* @author f00601390 +* @tc.desc The keyvalue is reported as a boolean list. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0400, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0400 start" << endl; + bool result = false; + char str[] = "hello"; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "str_key", str); + EventType eventType = EventType::BEHAVIOR; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":4", "\"str_key\":\"hello\""}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0400 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0400 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the Boolean List Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0500 +* @author f00601390 +* @tc.desc The keyvalue is reported as a boolean list. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0500, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0500 start" << endl; + bool result = false; + char str1[] = "hello"; + char str2[] = "world"; + char* strs[] = {str1, str2}; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringArrayParam(list, "str_arr_key", strs, sizeof(strs) / sizeof(strs[0])); + EventType eventType = EventType::BEHAVIOR; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":4", "\"str_arr_key\":[\"hello\",\"world\"]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0500 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0500 end" << endl; +} + +/** +* @tc.name Testing the Native Write Interface of the HiAppEvent, Reporting the Keyvalue of the Double Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0800 +* @author f00601390 +* @tc.desc The keyvalue type is double. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0800, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0800 start" << endl; + bool result = false; + double num = 30949.374; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddDoubleParam(list, "double_key", num); + EventType eventType = EventType::FAULT; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1", "\"double_key\":30949.374"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0800 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0800 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of a Double List. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0900 +* @author f00601390 +* @tc.desc The keyvalue is reported as a double list. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0900, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0900 start" << endl; + bool result = false; + double nums[] = {123.22, 30949.374, 131312.46464}; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddDoubleArrayParam(list, "double_arr_key", nums, sizeof(nums) / sizeof(nums[0])); + EventType eventType = EventType::STATISTIC; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":2", "\"double_arr_key\":[123.22,30949.374,131312.46464]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0900 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0900 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the KeyValue of the Floating Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1000 +* @author f00601390 +* @tc.desc The keyvalue type is float. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1000, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1000 start" << endl; + bool result = false; + float num = 234.5f; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddFloatParam(list, "float_key", num); + EventType eventType = EventType::STATISTIC; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":2", "\"float_key\":234.5"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1000 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1000 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of a Floating List. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1100 +* @author f00601390 +* @tc.desc The keyvalue is reported as a float list. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1100, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1100 start" << endl; + bool result = false; + float nums[] = {123.22f, 234.5f, 131312.46464f}; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddFloatArrayParam(list, "float_arr_key", nums, sizeof(nums) / sizeof(nums[0])); + EventType eventType = EventType::STATISTIC; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":2", "\"float_arr_key\":[123.22", "234.5", "131312.46"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1100 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1100 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reported When the Keyvalue Is of the Int Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1200 +* @author f00601390 +* @tc.desc The keyvalue is of the int type. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1200, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1200 start" << endl; + bool result = false; + int num = 1; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddInt8Param(list, "int8_key", num); + EventType eventType = EventType::SECURITY; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":3", "\"int8_key\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1200 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1200 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting of the int List Type of Keyvalue. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1300 +* @author f00601390 +* @tc.desc The keyvalue is reported as an int list. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1300, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1300 start" << endl; + bool result = false; + int8_t nums[] = {1, 10, 100}; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddInt8ArrayParam(list, "int8_arr_key", nums, sizeof(nums) / sizeof(nums[0])); + EventType eventType = EventType::SECURITY; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":3", "\"int8_arr_key\":[1,10,100]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1300 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1300 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1400 +* @author f00601390 +* @tc.desc The keyvalue type is long. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1400, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1400 start" << endl; + bool result = false; + int16_t num = 1; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddInt16Param(list, "int16_key", num); + EventType eventType = EventType::SECURITY; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":3", "\"int16_key\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1400 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1400 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1500 +* @author f00601390 +* @tc.desc The keyvalue type is long. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1500, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1500 start" << endl; + bool result = false; + int16_t nums[] = {1, 1000, 5000}; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddInt16ArrayParam(list, "int16_arr_key", nums, sizeof(nums) / sizeof(nums[0])); + EventType eventType = EventType::SECURITY; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":3", "\"int16_arr_key\":[1,1000,5000]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1500 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1500 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1600 +* @author f00601390 +* @tc.desc The keyvalue type is long. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1600, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1600 start" << endl; + bool result = false; + int32_t num = 1; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddInt32Param(list, "int32_key", num); + EventType eventType = EventType::SECURITY; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":3", "\"int32_key\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1600 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1600 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1700 +* @author f00601390 +* @tc.desc The keyvalue type is long. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1700, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1700 start" << endl; + bool result = false; + int32_t nums[] = {1, 100000, 500000}; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddInt32ArrayParam(list, "int32_arr_key", nums, sizeof(nums) / sizeof(nums[0])); + EventType eventType = EventType::SECURITY; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":3", "\"int32_arr_key\":[1,100000,500000]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1700 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1700 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1800 +* @author f00601390 +* @tc.desc The keyvalue type is long. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1800, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1800 start" << endl; + bool result = false; + int64_t num = 1; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddInt64Param(list, "int64_key", num); + EventType eventType = EventType::SECURITY; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":3", "\"int64_key\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1800 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1800 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1900 +* @author f00601390 +* @tc.desc The keyvalue type is long. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1900, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1900 start" << endl; + bool result = false; + int64_t nums[] = {1, 10000000, 50000000}; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddInt64ArrayParam(list, "int64_arr_key", nums, sizeof(nums) / sizeof(nums[0])); + EventType eventType = EventType::SECURITY; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":3", "\"int64_arr_key\":[1,10000000,50000000]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1900 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1900 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the string List Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2100 +* @author f00601390 +* @tc.desc The keyvalue is reported as a string list, 100 list parameters . +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2100, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2100 start" << endl; + bool result = false; + char* strs[100]; + for (int i = 0; i < 100; i++) { + strs[i] = new char[32]; + sprintf(strs[i], "hello_world_%d", i); + } + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringArrayParam(list, "str_arr_key", strs, sizeof(strs) / sizeof(strs[0])); + EventType eventType = EventType::BEHAVIOR; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":4"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2100 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2100 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the string Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2200 +* @author f00601390 +* @tc.desc The keyvalue is reported as a string, 8 * 1024 lenth. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2200, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2200 start" << endl; + bool result = false; + string strs = ""; + for (int i = 0; i < 1024; i++) { + strs.append("abcdefgh"); + } + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "str_key", strs.c_str()); + EventType eventType = EventType::BEHAVIOR; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":4"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2200 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2200 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the event name is null. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2300 +* @author f00601390 +* @tc.desc Reported event name is null. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2300, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2300 start" << endl; + char str[] = "hello"; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "str_key", str); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, NULL, eventType, list); + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(ret == -1); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2300 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the event name is empty. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2400 +* @author f00601390 +* @tc.desc Reported event name is empty. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2400, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2400 start" << endl; + char str[] = "hello"; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "str_key", str); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, "", eventType, list); + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(ret == -1); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2400 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the event name starts with number. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2500 +* @author f00601390 +* @tc.desc Reported event name starts with number. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2500, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2500 start" << endl; + char str[] = "hello"; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "str_key", str); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, "9527_test_event", eventType, list); + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(ret == -1); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2500 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, 33 parameters are reported. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2700 +* @author f00601390 +* @tc.desc key and values 33 parameters are reported. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2700, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2700 start" << endl; + bool result = false; + string getlogFile; + string path; + int maxLen = 33; + string keys[maxLen]; + string values[maxLen]; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + for (int i = 0; i <= maxLen; i++) { + keys[i] = "key" + std::to_string(i); + values[i] = "value" + std::to_string(i); + OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str()); + } + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1", "\"key31\":\"value31\"", "\"key15\":\"value15\""}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2700 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(ret == 5); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2700 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, key and value is empty. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2800 +* @author f00601390 +* @tc.desc key and value is empty. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2800, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2800 start" << endl; + bool result = false; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "", ""); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2800 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + ASSERT_TRUE(ret == 1); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2800 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, key is not string type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2900 +* @author f00601390 +* @tc.desc key is not string type. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2900, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2900 start" << endl; + bool result = false; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "", "hello"); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2900 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + ASSERT_TRUE(ret == 1); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2900 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, key start with number. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3000 +* @author f00601390 +* @tc.desc key start with number. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3000, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3000 start" << endl; + bool result = false; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "9527_hello", "world"); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3000 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + ASSERT_TRUE(ret == 1); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3000 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, Reporting the Key value of the string Type. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3100 +* @author f00601390 +* @tc.desc The keyvalue is reported as a string, 8 * 1024 + 1 length. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3100, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3100 start" << endl; + bool result = false; + string strs = ""; + for (int i = 0; i < 1024; i++) { + strs.append("abcdefgh"); + } + strs.append("a"); + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, "str_key", strs.c_str()); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3100 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + ASSERT_TRUE(ret == 4); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3100 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, key and value is NULL. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3200 +* @author f00601390 +* @tc.desc key and value is NULL. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3200, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3200 start" << endl; + bool result = false; + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringParam(list, NULL, NULL); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3200 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(ret == 0); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3200 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, List Type Reporting,101 List Parameters. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3300 +* @author f00601390 +* @tc.desc 101 List Parameters. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3300, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3300 start" << endl; + bool result = false; + char* strs[101]; + for (int i = 0; i < 101; i++) { + strs[i] = new char[32]; + sprintf(strs[i], "hello_world_%d", i); + } + string getlogFile; + string path; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddStringArrayParam(list, "str_arr_key", strs, sizeof(strs) / sizeof(strs[0])); + EventType eventType = EventType::BEHAVIOR; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":4", + "\"str_arr_key\":[\"hello_world_0\",\"hello_world_1\",\"hello_world_2\"]", "hello_world_99"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3300 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(ret == 6); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3300 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, 32 parameters are reported. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3400 +* @author f00601390 +* @tc.desc key and values 32 parameters are reported. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3400, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3400 start" << endl; + bool result = false; + string getlogFile; + string path; + int maxLen = 32; + string keys[maxLen+1]; + string values[maxLen+1]; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + for (int i = 0; i <= maxLen; i++) { + keys[i] = "key" + std::to_string(i); + values[i] = "value" + std::to_string(i); + OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str()); + } + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + string fileinfo = ""; + fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1", "\"key31\":\"value31\"", "\"key15\":\"value15\"", + "\"key0\":\"value0\""}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3400 file error" << std::endl; + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(ret == 5); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3400 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, 32 parameters are reported. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3500 +* @author f00601390 +* @tc.desc key and values 32 parameters are reported. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3500, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3500 start" << endl; + string getlogFile; + string path; + OH_HiAppEvent_Configure("max_storage", "10M"); + int maxLen = 32; + string keys[maxLen+1]; + string values[maxLen+1]; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + std::vector cmdret; + time_t nowtime; + struct tm* p; + time(&nowtime); + p = localtime(&nowtime); + char s[25]; + sprintf(s, "app_event_%d%02d%02d.log", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday); + string fname = s; + string cmd = "dd if=/dev/zero of=/data/test/hiappevent/" + fname + " bs=11M count=1"; + ExecCmdWithRet(cmd, cmdret); + ParamList list = OH_HiAppEvent_CreateParamList(); + for (int i = 0; i <= maxLen; i++) { + keys[i] = "key" + std::to_string(i); + values[i] = "value" + std::to_string(i); + OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str()); + } + EventType eventType = EventType::FAULT; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + bool result = false; + string fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1", "\"key31\":\"value31\"", "\"key15\":\"value15\"", + "\"key0\":\"value0\""}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3500 end" << endl; +} + +/** +* @tc.name HiAppEvent Native Write Interface Test, 32 parameters are reported. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3500 +* @author f00601390 +* @tc.desc key and values 32 parameters are reported. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3600, Function|MediumTest|Level4) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3600 start" << endl; + string getlogFile; + string path; + OH_HiAppEvent_Configure("max_storage", "1M"); + int maxLen = 32; + string keys[maxLen+1]; + string values[maxLen+1]; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + std::vector cmdret; + time_t nowtime; + struct tm* p; + time(&nowtime); + p = localtime(&nowtime); + char s[25]; + sprintf(s, "app_event_%d%02d%02d.log", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday); + string fname = s; + string cmd = "dd if=/dev/zero of=/data/test/hiappevent/" + fname + " bs=1.5M count=1"; + ExecCmdWithRet(cmd, cmdret); + ParamList list = OH_HiAppEvent_CreateParamList(); + for (int i = 0; i <= maxLen; i++) { + keys[i] = "key" + std::to_string(i); + values[i] = "value" + std::to_string(i); + OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str()); + } + EventType eventType = EventType::FAULT; + OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + getlogFile = accumulate(file.begin(), file.end(), getlogFile); + path = logPath + getlogFile; + bool result = false; + string fileinfo = ReadFile(path); + std::vector para = {"test_event", "\"type_\":1", "\"key31\":\"value31\"", "\"key15\":\"value15\"", + "\"key0\":\"value0\""}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(result); + OH_HiAppEvent_Configure("max_storage", "10M"); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3600 end" << endl; +} + +/** +* @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue +* is of the boolean type and the bool value is true. +* @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3700 +* @author f00601390 +* @tc.desc The keyvalue is of the boolean type and the bool value is false. +*/ +HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3700, Function|MediumTest|Level3) { + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3700 start" << endl; + OH_HiAppEvent_Configure("disable", "true"); + bool boolean = true; + OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/"); + ParamList list = OH_HiAppEvent_CreateParamList(); + OH_HiAppEvent_AddBoolParam(list, "bool_key", boolean); + EventType eventType = EventType::FAULT; + int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list); + std::vector file; + file = getfileinpath(logPath); + OH_HiAppEvent_DestroyParamList(list); + ASSERT_TRUE(file.size() == 0); + ASSERT_TRUE(ret == -99); + OH_HiAppEvent_Configure("disable", "false"); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3700 end" << endl; +} diff --git a/hiviewdfx/hiappeventtest/hiappeventcpptest/Test.json b/hiviewdfx/hiappeventtest/hiappeventcpptest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..079ec333118556bc8856e2b8ac060ba9c95cd3f3 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventcpptest/Test.json @@ -0,0 +1,18 @@ +{ + "kits": [ + { + "push": [ + "HiAppEventCPPTest->/data/local/tmp/HiAppEventCPPTest" + ], + "type": "PushKit" + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "HiAppEventCPPTest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for HiAppEventCPPTest Tests" +} \ No newline at end of file diff --git a/hiviewdfx/hilogjstest/BUILD.gn b/hiviewdfx/hilogtest/hilogjstest/BUILD.gn similarity index 100% rename from hiviewdfx/hilogjstest/BUILD.gn rename to hiviewdfx/hilogtest/hilogjstest/BUILD.gn diff --git a/hiviewdfx/hilogjstest/Test.json b/hiviewdfx/hilogtest/hilogjstest/Test.json similarity index 100% rename from hiviewdfx/hilogjstest/Test.json rename to hiviewdfx/hilogtest/hilogjstest/Test.json diff --git a/hiviewdfx/hilogjstest/signature/openharmony_sx.p7b b/hiviewdfx/hilogtest/hilogjstest/signature/openharmony_sx.p7b similarity index 100% rename from hiviewdfx/hilogjstest/signature/openharmony_sx.p7b rename to hiviewdfx/hilogtest/hilogjstest/signature/openharmony_sx.p7b diff --git a/hiviewdfx/hilogjstest/src/main/config.json b/hiviewdfx/hilogtest/hilogjstest/src/main/config.json similarity index 100% rename from hiviewdfx/hilogjstest/src/main/config.json rename to hiviewdfx/hilogtest/hilogjstest/src/main/config.json diff --git a/hiviewdfx/hilogjstest/src/main/js/default/app.js b/hiviewdfx/hilogtest/hilogjstest/src/main/js/default/app.js similarity index 100% rename from hiviewdfx/hilogjstest/src/main/js/default/app.js rename to hiviewdfx/hilogtest/hilogjstest/src/main/js/default/app.js diff --git a/hiviewdfx/hilogjstest/src/main/js/default/i18n/en-US.json b/hiviewdfx/hilogtest/hilogjstest/src/main/js/default/i18n/en-US.json similarity index 100% rename from hiviewdfx/hilogjstest/src/main/js/default/i18n/en-US.json rename to hiviewdfx/hilogtest/hilogjstest/src/main/js/default/i18n/en-US.json diff --git a/hiviewdfx/hilogjstest/src/main/js/default/i18n/zh-CN.json b/hiviewdfx/hilogtest/hilogjstest/src/main/js/default/i18n/zh-CN.json similarity index 100% rename from hiviewdfx/hilogjstest/src/main/js/default/i18n/zh-CN.json rename to hiviewdfx/hilogtest/hilogjstest/src/main/js/default/i18n/zh-CN.json diff --git a/hiviewdfx/hilogjstest/src/main/js/default/pages/index/index.css b/hiviewdfx/hilogtest/hilogjstest/src/main/js/default/pages/index/index.css similarity index 100% rename from hiviewdfx/hilogjstest/src/main/js/default/pages/index/index.css rename to hiviewdfx/hilogtest/hilogjstest/src/main/js/default/pages/index/index.css diff --git a/hiviewdfx/hilogjstest/src/main/js/default/pages/index/index.hml b/hiviewdfx/hilogtest/hilogjstest/src/main/js/default/pages/index/index.hml similarity index 100% rename from hiviewdfx/hilogjstest/src/main/js/default/pages/index/index.hml rename to hiviewdfx/hilogtest/hilogjstest/src/main/js/default/pages/index/index.hml diff --git a/hiviewdfx/hilogjstest/src/main/js/default/pages/index/index.js b/hiviewdfx/hilogtest/hilogjstest/src/main/js/default/pages/index/index.js similarity index 100% rename from hiviewdfx/hilogjstest/src/main/js/default/pages/index/index.js rename to hiviewdfx/hilogtest/hilogjstest/src/main/js/default/pages/index/index.js diff --git a/hiviewdfx/hilogjstest/src/main/js/default/test/HilogJsTest.js b/hiviewdfx/hilogtest/hilogjstest/src/main/js/default/test/HilogJsTest.js similarity index 100% rename from hiviewdfx/hilogjstest/src/main/js/default/test/HilogJsTest.js rename to hiviewdfx/hilogtest/hilogjstest/src/main/js/default/test/HilogJsTest.js diff --git a/hiviewdfx/hilogjstest/src/main/js/default/test/List.test.js b/hiviewdfx/hilogtest/hilogjstest/src/main/js/default/test/List.test.js similarity index 100% rename from hiviewdfx/hilogjstest/src/main/js/default/test/List.test.js rename to hiviewdfx/hilogtest/hilogjstest/src/main/js/default/test/List.test.js diff --git a/hiviewdfx/hilogjstest/src/main/resources/base/element/string.json b/hiviewdfx/hilogtest/hilogjstest/src/main/resources/base/element/string.json similarity index 100% rename from hiviewdfx/hilogjstest/src/main/resources/base/element/string.json rename to hiviewdfx/hilogtest/hilogjstest/src/main/resources/base/element/string.json diff --git a/hiviewdfx/hilogjstest/src/main/resources/base/media/icon.png b/hiviewdfx/hilogtest/hilogjstest/src/main/resources/base/media/icon.png similarity index 100% rename from hiviewdfx/hilogjstest/src/main/resources/base/media/icon.png rename to hiviewdfx/hilogtest/hilogjstest/src/main/resources/base/media/icon.png diff --git a/hiviewdfx/hilogtest/hilogndktest/BUILD.gn b/hiviewdfx/hilogtest/hilogndktest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..6ad1ed6f71306522002e410831748d04bf8c7bb8 --- /dev/null +++ b/hiviewdfx/hilogtest/hilogndktest/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (C) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") +module_output_path = "hits/hilogndktest" + +config("hilogndktest_config") { + visibility = [ ":*" ] + include_dirs = [ + "//base/hiviewdfx/hilog/interfaces/native/kits/include", + "//utils/native/base/include/", + ] +} +ohos_moduletest_suite("hilogndktest") { + module_out_path = module_output_path + sources = [ "hilogndktest.cpp" ] + deps = [ + "//base/hiviewdfx/hilog/frameworks/hilog_ndk:hilog_ndk", + "//base/hiviewdfx/hilog/interfaces/native/kits:libhilog_ndk", + "//utils/native/base:utils", + "//third_party/googletest:gtest_main", + ] + configs = [ ":hilogndktest_config" ] +} diff --git a/hiviewdfx/hilogtest/hilogndktest/Test.json b/hiviewdfx/hilogtest/hilogndktest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..f4fafaa3414f3358c797d71161a03db23f50bc98 --- /dev/null +++ b/hiviewdfx/hilogtest/hilogndktest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hilogndktest demo Tests", + "driver": { + "type": "CppTest", + "native-test-timeout": "120000", + "module-name": "hilogndktest", + "runtime-hint": "ls", + "native-test-device-path": "/data/local/tmp" + }, + "kits": [ + { + "push": [ + "hilogndktest->/data/local/tmp/hilogndktest" + ], + "type": "PushKit" + } + ] +} diff --git a/hiviewdfx/hilogtest/hilogndktest/hilogndktest.cpp b/hiviewdfx/hilogtest/hilogndktest/hilogndktest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f1e8e1d80615ff508d287872c59de731a40c4ce8 --- /dev/null +++ b/hiviewdfx/hilogtest/hilogndktest/hilogndktest.cpp @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "hilog/log.h" + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0xD003e00 + +using namespace std; +using namespace testing::ext; + +class hilogndktest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void hilogndktest::SetUp() +{ +} +void hilogndktest::TearDown() +{ +} +void hilogndktest::SetUpTestCase() +{ +} +void hilogndktest::TearDownTestCase() +{ +} + +/** + * @tc.number : DFX_DFT_HILOGNDK_0100 + * @tc.name : HILOGNDK_TEST + * @tc.desc : HILOGNDK_TEST + */ +HWTEST_F(hilogndktest, OH_LOG_Print_CHECK, Function | MediumTest | Level1) +{ + LogType type = LOG_APP; + LogLevel level = LOG_ERROR; + int ret = OH_LOG_Print(type, level, 0xD003e00, "testtag0testtag1testtag2", "string:for hilog test %{private}s", "name"); + ASSERT_TRUE(ret == 85); +} + +/** + * @tc.number : DFX_DFT_HILOGNDK_0200 + * @tc.name : HILOGNDK_TEST + * @tc.desc : HILOGNDK_TEST + */ +HWTEST_F(hilogndktest, OH_LOG_IsLoggable_CHECK, Function | MediumTest | Level1) +{ + LogLevel level = LOG_DEBUG; + const char *LOG_TAG = "testtag0testtag0testtag0testta"; + bool res = OH_LOG_IsLoggable(0xD003e00, LOG_TAG, level); + ASSERT_TRUE(res == false); +} + diff --git a/hiviewdfx/utils/native/BUILD.gn b/hiviewdfx/utils/native/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..4ef7b2c239484f9b349edf75bec530bbeb760898 --- /dev/null +++ b/hiviewdfx/utils/native/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (C) 2021-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//test/xts/tools/build/suite.gni") + +############################################################################### +config("utils_config") { + visibility = [ ":*" ] + include_dirs = [ + "//third_party/cJSON/", + "//third_party/zlib/", + "//utils/native/base/", + ] +} + +sources_common = [ "file_utils.cpp" ] +ohos_static_library("utilskit") { + sources = sources_common + configs = [ ":utils_config" ] + + #external_deps = [ "hilog:libhilog" ] + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//base/hiviewdfx/hiview/base:hiviewbase", + "//utils/native/base:utils", + ] +} diff --git a/hiviewdfx/utils/native/file_utils.cpp b/hiviewdfx/utils/native/file_utils.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c486557511440556a899798b3fc44d485f89a376 --- /dev/null +++ b/hiviewdfx/utils/native/file_utils.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef TEST_COMMON_H +#define TEST_COMMON_H +#include "file_utils.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "include/securec.h" +#include "string_util.h" + +using namespace OHOS::HiviewDFX; +int ExecCmdWithRet(std::string cmd, std::vector &resvec) +{ + if (cmd.size() == 0) { + return 0; + } + + std::cout<< "cmd is " + cmd < cmdret; + ExecCmdWithRet(cmd, cmdret); +} + +void CmdRun(std::string cmd, std::string &result) +{ + std::vector cmdret; + int resultlen; + int i = 0; + std::string rst; + resultlen = ExecCmdWithRet(cmd, cmdret); + while (i < resultlen) { + rst = rst + cmdret[i]; + i = i + 1; + } + result = rst; +} + +void CleanCmd() +{ + std::string cmdResult; + std::string cleanCmd = "hilog -r"; + CmdRun(cleanCmd, cmdResult); + std::cout << cmdResult; +} + +std::string ExecuteCmd(std::string cmd) +{ + std::vector cmdret; + int resultlen; + int i = 0; + std::string rst; + resultlen = ExecCmdWithRet(cmd, cmdret); + while (i < resultlen) { + rst = rst + cmdret[i] + "\n"; + i = i + 1; + } + return rst; +} +void SaveCmdOutput(std::string cmd, std::string saveFile) +{ + std::fstream fstr(saveFile, std::ios::out); + std::string cmdRet = ExecuteCmd(cmd); + fstr << cmdRet; + fstr.close(); +} +void RedirecthiLog(std::string &hilogredirect, std::string &timeout) +{ + unsigned long i; + std::vector cmdret; + unsigned long cmdretlen; + std::string cmd = "rm " + hilogredirect; + cmdretlen = ExecCmdWithRet(cmd, cmdret); + for (i = 0; i < cmdretlen; i++) { + std::cout<" + hilogredirect; + std::cout< ¶, std::string info) +{ + if (info.empty()) { + return false; + } + bool result = false; + unsigned long matchcnt = 0; + for (unsigned long i = 0; i < para.size(); i++) { + if (int(info.find(para[i])) >= 0) { + matchcnt++; + } + } + std::cout<< matchcnt <= 0) { + len--; + } + if (len >= 0 && x[len] > y[len]) { + return false; + } + return true; +} + +int GetTxtLine(std::string filename) +{ + FILE *fd = fopen(filename.c_str(), "r"); + int count = 0; + if (fd != nullptr) { + while (!feof(fd)) { + if (fgetc(fd) == '\n') { + count++; + } + } + } + std::cout << count << std::endl; + if (fd != nullptr) { + fclose(fd); + } + return count; +} + +std::string ReadFile(std::string filename) +{ + std::ifstream ifile(filename); + std::ostringstream buf; + char ch; + if (ifile.fail()) { + std::cout<<"open file fail!"< getfileinpath(std::string path) +{ + std::vector filelist; + DIR *dir; + struct dirent *pdirent; + dir = opendir(path.c_str()); + if (dir != nullptr) { + while ((pdirent = readdir(dir)) != nullptr) { + if (strncmp(pdirent->d_name, ".", strlen(pdirent->d_name)) == 0 || + strncmp(pdirent->d_name, "..", strlen(pdirent->d_name)) == 0) { + continue; + } else if (pdirent->d_type == 4) { + continue; + } else { + filelist.push_back(pdirent->d_name); + } + } + closedir(dir); + } + return filelist; +} +#endif diff --git a/hiviewdfx/utils/native/file_utils.h b/hiviewdfx/utils/native/file_utils.h new file mode 100755 index 0000000000000000000000000000000000000000..e7800e68a8d05e837f2bd9f33e1cbbb24e393605 --- /dev/null +++ b/hiviewdfx/utils/native/file_utils.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_ +#define HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool CheckInfo(std::vector ¶, std::string eventinfo); +int ExecCmdWithRet(std::string cmd, std::vector &resvec); +std::string ReadFile(std::string filename); +void RedirecthiLog(std::string &hilogredirect, std::string &timeout); +void ExeCmd(std::string cmd); +void CmdRun(std::string cmd, std::string &result); +std::string ExecuteCmd(std::string cmd); +bool CompareString(const std::string& x, const std::string& y); +int GetTxtLine(std::string filename); +std::string ReadFile(std::string filename); +void CleanCmd(); +std::string ReadOneLine(std::string m_path, char* rBuf, int n); +void SaveCmdOutput(std::string cmd, std::string saveFile); +std::vector getfileinpath(std::string path); +#endif // HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_