提交 46a81305 编写于 作者: C chenxuihui

napi xts add

Signed-off-by: Nchenxuihui <chenxuhui2@huawei.com>
上级 2b4dfdd8
......@@ -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",
......
# 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" ]
}
/*
* 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 <numeric>
#include <iostream>
#include <gtest/gtest.h>
#include <vector>
#include <map>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#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<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
string fileinfo = "";
fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
bool result = false;
string fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> 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<std::string> file;
file = getfileinpath(logPath);
getlogFile = accumulate(file.begin(), file.end(), getlogFile);
path = logPath + getlogFile;
bool result = false;
string fileinfo = ReadFile(path);
std::vector<std::string> 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<std::string> 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;
}
{
"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
# 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" ]
}
{
"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"
}
]
}
/**
* 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 <gtest/gtest.h>
#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);
}
# 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",
]
}
/*
* 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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <chrono>
#include <dirent.h>
#include <condition_variable>
#include <vector>
#include "include/securec.h"
#include "string_util.h"
using namespace OHOS::HiviewDFX;
int ExecCmdWithRet(std::string cmd, std::vector<std::string> &resvec)
{
if (cmd.size() == 0) {
return 0;
}
std::cout<< "cmd is " + cmd <<std::endl;
if ((cmd.find("hilog") == std::string::npos) && (cmd.find("hidumper") == std::string::npos)
&& (cmd.find("ps") == std::string::npos) && (cmd.find("rm") == std::string::npos) &&
(cmd.find("hiperf") == std::string::npos) && (cmd.find("hisysevent") == std::string::npos) &&
(cmd.find("mkdir") == std::string::npos) && (cmd.find("dd") == std::string::npos)) {
std::cout<<"unsupport cmd!" + cmd <<std::endl;
return 0;
}
resvec.clear();
FILE *pp = popen(cmd.c_str(), "r");
if (pp == nullptr) {
return -1;
}
char tmp[1024];
while (fgets(tmp, sizeof(tmp), pp) != nullptr) {
if (tmp[strlen(tmp) - 1] == '\n') {
tmp[strlen(tmp) - 1] = '\0';
}
resvec.push_back(tmp);
}
pclose(pp);
return resvec.size();
}
void ExeCmd(std::string cmd)
{
std::vector<std::string> cmdret;
ExecCmdWithRet(cmd, cmdret);
}
void CmdRun(std::string cmd, std::string &result)
{
std::vector<std::string> 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<std::string> 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<std::string> cmdret;
unsigned long cmdretlen;
std::string cmd = "rm " + hilogredirect;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
for (i = 0; i < cmdretlen; i++) {
std::cout<<cmdret[i].c_str()<<std::endl;
}
cmd = "timeout " + timeout + " hilog >" + hilogredirect;
std::cout<<cmd<<std::endl;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
for (i = 0; i < cmdretlen; i++) {
std::cout<<cmdret[i].c_str()<<std::endl;
}
}
bool CheckInfo(std::vector<std::string> &para, 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 <<std::endl;
if (matchcnt == para.size()) {
result = true;
}
return result;
}
bool CompareString(const std::string& x, const std::string& y)
{
int len = x.length() - 1;
while (x[len] == y[len] && len >= 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!"<<std::endl;
return "";
}
while (buf && ifile.get(ch)) {
buf.put(ch);
}
ifile.close();
return buf.str();
}
std::vector<std::string> getfileinpath(std::string path)
{
std::vector<std::string> 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
/*
* 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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <chrono>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <vector>
bool CheckInfo(std::vector<std::string> &para, std::string eventinfo);
int ExecCmdWithRet(std::string cmd, std::vector<std::string> &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<std::string> getfileinpath(std::string path);
#endif // HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册