HiSysEventCPPTest.cpp 27.5 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * 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 "hilog/log.h"
#include <gtest/gtest.h>

#include "file_utils.h"
#include "hisysevent.h"

using namespace testing;
using namespace testing::ext;
using namespace std;
using namespace OHOS::HiviewDFX;
namespace {
string g_key = "key";
27
string g_reDiRectTimeout = "6";
M
mamingshuai 已提交
28 29 30 31 32 33 34 35
string g_hiLogRedirect = "/data/local/tmp/hilogredirect.log";
}
class HiSysEventCPPTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
Z
zhuqingxi 已提交
36
    void RedHiSysEventLog(std::string &hilogredirect, std::string &timeout);
M
mamingshuai 已提交
37 38 39 40 41
private:
};
void HiSysEventCPPTest::SetUp()
{
    std::cout << "SetUp" << std::endl;
Z
zhuqingxi 已提交
42
    CleanCmd();
M
mamingshuai 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
}
void HiSysEventCPPTest::TearDown()
{
    std::cout << "TearDown" << std::endl;
    std::vector<std::string> cmdret;
    string cmd = "rm " + g_hiLogRedirect;
    ExecCmdWithRet(cmd, cmdret);
}
void HiSysEventCPPTest::SetUpTestCase()
{
    std::cout << "SetUpTestCase" << std::endl;
    std::vector<std::string> cmdret;
    string cmd = "mkdir /data/local/tmp/";
    ExecCmdWithRet(cmd, cmdret);
}
void HiSysEventCPPTest::TearDownTestCase()
{
    std::cout << "TearDownTestCase" << std::endl;
}
Z
zhuqingxi 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
void HiSysEventCPPTest::RedHiSysEventLog(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 | grep HISYSEVENT >" + hilogredirect;
    std::cout<<cmd<<std::endl;
    cmdretlen = ExecCmdWithRet(cmd, cmdret);
    for (i = 0; i < cmdretlen; i++) {
        std::cout<<cmdret[i].c_str()<<std::endl;
    }
}
M
mamingshuai 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92
/**
* @tc.name HiSysEvent Native Write Interface Test, Reported When the KeyValue Is of the
*       boolean Type and the bool Value Is False
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0100
* @tc.desc The keyvalue is of the boolean type and the bool value is false.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0100, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 start" << endl;
    bool result = false;
    bool param = false;
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
93
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
94 95
    string fileinfo;
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
96
    std::vector<std::string> para = {"AAFWK", "eventNameDemo", "\"type_\":1", "\"key\":0"};
M
mamingshuai 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    if (!fileinfo.empty()) {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 end" << endl;
}
/**
* @tc.name HiSysEvent Native Write Interface Test, Reported When the KeyValue Is of
*       the boolean Type and the bool Value Is False
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0200
* @tc.desc The keyvalue is of the boolean type and the bool value is true.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0200, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 start" << endl;
    bool result = false;
    bool param = true;
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::APPEXECFWK;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
119
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
120 121
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
122
    std::vector<std::string> para = {"APPEXECFWK", "eventNameDemo", "\"type_\":1", "\"key\":1"};
M
mamingshuai 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Boolean List Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0300
* @tc.desc The value of keyvalue is a boolean list.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0300, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 start" << endl;
    bool result = false;
    bool param = false;
    std::vector<bool> test;
    test.push_back(param);
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::ACCOUNT;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
146
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
147 148
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
149
    std::vector<std::string> para = {"ACCOUNT", "eventNameDemo", "\"type_\":1", "\"key\":[0]"};
M
mamingshuai 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Char Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0400
* @tc.desc The keyvalue is of the char type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0400, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 start" << endl;
    bool result = false;
    char param = 'a';
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::OTHERS;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
171
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
172 173
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
174
    std::vector<std::string> para = {"OTHERS", "eventNameDemo", "\"type_\":1", "\"key\":97"};
M
mamingshuai 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0500
* @tc.desc keyvalue is of the char list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0500, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 start" << endl;
    bool result = false;
    char param = 'a';
    std::vector<char> test;
    test.push_back(param);
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::WEARABLE;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
198
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
199 200
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
201
    std::vector<std::string> para = {"WEARABLE", "eventNameDemo", "\"type_\":1", "\"key\":[97]"};
M
mamingshuai 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 end" << endl;
}
/**
* @tc.name HiSysEvent Natvie Write Interface Test, Reported When the KeyValue Is of the Double Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0600
* @tc.desc The keyvalue is of the double type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0600, Function|MediumTest|Level2)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 start" << endl;
    bool result = false;
    double param = 30949.374;
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::WEARABLE_HARDWARE;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
223
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
224 225
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
226
    std::vector<std::string> para = {"WEARABLEHW", "eventNameDemo", "\"type_\":1", "\"key\":30949.4"};
M
mamingshuai 已提交
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0700
* @tc.desc keyvalue is of the char list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0700, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 start" << endl;
    bool result = false;
    double param = 30949.374;
    std::vector<double> test;
    test.push_back(param);
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::USB;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
250
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
251 252
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
253
    std::vector<std::string> para = {"USB", "eventNameDemo", "\"type_\":1", "\"key\":[30949.4]"};
M
mamingshuai 已提交
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Floating Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0800
* @tc.desc The keyvalue is of the float type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0800, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 start" << endl;
    bool result = false;
    float param = 230.47;
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::UPDATE;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
275
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
276 277
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
278
    std::vector<std::string> para = {"UPDATE", "eventNameDemo", "\"type_\":1", "\"key\":230.47"};
M
mamingshuai 已提交
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0900
* @tc.desc keyvalue is of the char list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0900, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 start" << endl;
    bool result = false;
    float param = 230.47;
    std::vector<float> test;
    test.push_back(param);
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::TELEPHONY;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
302
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
303 304
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
305
    std::vector<std::string> para = {"TELEPHONY", "eventNameDemo", "\"type_\":1", "\"key\":[230.47]"};
M
mamingshuai 已提交
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Int Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1000
* @tc.desc The keyvalue is of the int type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1000, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 start" << endl;
    bool result = false;
    int param = 100;
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::STARTUP;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
327
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
328 329
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
330
    std::vector<std::string> para = {"STARTUP", "eventNameDemo", "\"type_\":1", "\"key\":100"};
M
mamingshuai 已提交
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 end" << endl;
}
/**
* @tc.name HiSysEvent Natvie Write Interface Test, Reporting of the int List of KeyValues
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1100
* @tc.desc keyvalue is of the int list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1100, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 start" << endl;
    bool result = false;
    int param = 100;
    std::vector<int> test;
    test.push_back(param);
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SOURCE_CODE_TRANSFORMER;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
354
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
355 356
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
357
    std::vector<std::string> para = {"SRCTRANSFORMER", "eventNameDemo", "\"type_\":1", "\"key\":[100]"};
M
mamingshuai 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Long Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1200
* @tc.desc The keyvalue is of the long type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1200, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 start" << endl;
    bool result = false;
    long param = 1000000;
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SENSORS;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
379
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
380 381
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
382
    std::vector<std::string> para = {"SENSORS", "eventNameDemo", "\"type_\":1", "\"key\":1000000"};
M
mamingshuai 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of the Long Key Value
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1300
* @tc.desc The keyvalue is of the long list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1300, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 start" << endl;
    bool result = false;
    long param = 1000000;
    std::vector<long> test;
    test.push_back(param);
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SECURITY;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
406
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
407 408
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
409
    std::vector<std::string> para = {"SECURITY", "eventNameDemo", "\"type_\":1", "\"key\":[1000000]"};
M
mamingshuai 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Short Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1400
* @tc.desc The keyvalue is of the short type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1400, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0250 start" << endl;
    bool result = false;
    short param = 10;
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::ROUTER;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
431
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
432 433
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
434
    std::vector<std::string> para = {"ROUTER", "eventNameDemo", "\"type_\":1", "\"key\":10"};
M
mamingshuai 已提交
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1400 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1400 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of Short Key Values
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1500
* @tc.desc The keyvalue is of the short list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1500, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 start" << endl;
    bool result = false;
    short param = 10;
    std::vector<short> test;
    test.push_back(param);
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::POWERMGR;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
458
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
459 460
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
461
    std::vector<std::string> para = {"POWERMGR", "eventNameDemo", "\"type_\":2", "\"key\":[10]"};
M
mamingshuai 已提交
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the String Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1600
* @tc.desc The keyvalue is of the string type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1600, Function|MediumTest|Level2)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 start" << endl;
    bool result = false;
    string param = "abc";
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::NOTIFICATION;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
483
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
484 485
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
486
    std::vector<std::string> para = {"NOTIFICATION", "eventNameDemo", "\"type_\":2", "\"key\":\"abc\""};
M
mamingshuai 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of Short Key Values
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1700
* @tc.desc The keyvalue is of the short list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1700, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 start" << endl;
    bool result = false;
    string param = "abc";
    std::vector<string> test;
    test.push_back(param);
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::SECURITY;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
510
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
511 512
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
513
    std::vector<std::string> para = {"MULTIMODALINPUT", "eventNameDemo", "\"type_\":3", "\"key\":[\"abc\"]"};
M
mamingshuai 已提交
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 end" << endl;
}
/**
* @tc.name HiSysEvent Natvie Write Interface Test, Reporting the List of 20 List Parameters When the Key Value Is String
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1800
* @tc.desc The keyvalue is reported as a string list. There are 20 list parameters.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1800, Function|MediumTest|Level4)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0290 start" << endl;
    bool result = false;
    string param = "abc";
    std::vector<string> test;
    for (int i = 0; i < 20; i++) {
        test.push_back(param);
    }
    string str = "\"key\":[";
    for (int i = 0; i < 19; i++) {
        str = str + "\"abc\",";
    }
    str = str + "\"abc\"]";
    GTEST_LOG_(INFO) << str << endl;
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::SECURITY;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
Z
zhuqingxi 已提交
545
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
546 547
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
548
    std::vector<std::string> para = {"MULTIMEDIA", "eventNameDemo", "\"type_\":3", str};
M
mamingshuai 已提交
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1800 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1800 end" << endl;
}
/**
* @tc.name In the HiSysEvent Natvie Write interface test, 32 parameters are reported for each type of keyvalue.
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_2000
* @tc.desc The keyvalue parameter has 32 parameters for each type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_2000, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 start" << endl;
    bool result = false;
    string param = "abc";
    string str = "";
    for (int i=0; i < 31; i++){
        str = str + "\"key\":\"abc\",";
    }
    str += "\"key\":\"abc\"";
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MSDP;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype,
        g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
        g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
        g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
        g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
        g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
        g_key, param, g_key, param);
Z
zhuqingxi 已提交
581
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
582 583
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
584
    std::vector<std::string> para = {"MSDP", "eventNameDemo", "\"type_\":4", str};
M
mamingshuai 已提交
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 end" << endl;
}
/**
* @tc.name In the test of the HiSysEvent Natvie Write interface, the key value is a string of 256 characters.
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_2200
* @tc.desc The keyvalue is a string of 256 characters.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_2200, Function|MediumTest|Level3)
{
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 start" << endl;
    bool result = false;
    string param = "";
    for (int i = 0; i < 256; i++) {
        param += "a";
    }
    string domain = OHOS::HiviewDFX::HiSysEvent::Domain::LOCATION;
    OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
    OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
Z
zhuqingxi 已提交
609
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
610 611
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
612
    std::vector<std::string> para = {"LOCATION", "eventNameDemo", "\"type_\":4", g_key, param};
M
mamingshuai 已提交
613 614 615 616 617 618 619 620
    if (fileinfo != "") {
        result = CheckInfo(para, fileinfo);
    } else {
        std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 file error" << std::endl;
    }
    ASSERT_TRUE(result);
    GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 end" << endl;
}