HiSysEventCPPTest.cpp 27.7 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 27 28 29 30 31 32 33 34 35
/*
 * 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";
string g_reDiRectTimeout = "5";
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
private:
};
void HiSysEventCPPTest::SetUp()
{
    std::cout << "SetUp" << std::endl;
    std::vector<std::string> cmdret;
    string cmd = "hilog -r";
    ExecCmdWithRet(cmd, cmdret);
    cmd = "setprop persist.sys.hilog.debug.on false";
    ExecCmdWithRet(cmd, cmdret);
}
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 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
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 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96
/**
* @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 已提交
97
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
98 99
    string fileinfo;
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
100
    std::vector<std::string> para = {"AAFWK", "eventNameDemo", "\"type_\":1", "\"key\":0"};
M
mamingshuai 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    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 已提交
123
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
124 125
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
126
    std::vector<std::string> para = {"APPEXECFWK", "eventNameDemo", "\"type_\":1", "\"key\":1"};
M
mamingshuai 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    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 已提交
150
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
151 152
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
153
    std::vector<std::string> para = {"ACCOUNT", "eventNameDemo", "\"type_\":1", "\"key\":[0]"};
M
mamingshuai 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    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 已提交
175
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
176 177
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
178
    std::vector<std::string> para = {"OTHERS", "eventNameDemo", "\"type_\":1", "\"key\":97"};
M
mamingshuai 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    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 已提交
202
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
203 204
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
205
    std::vector<std::string> para = {"WEARABLE", "eventNameDemo", "\"type_\":1", "\"key\":[97]"};
M
mamingshuai 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
    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 已提交
227
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
228 229
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
230
    std::vector<std::string> para = {"WEARABLEHW", "eventNameDemo", "\"type_\":1", "\"key\":30949.4"};
M
mamingshuai 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
    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 已提交
254
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
255 256
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
257
    std::vector<std::string> para = {"USB", "eventNameDemo", "\"type_\":1", "\"key\":[30949.4]"};
M
mamingshuai 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
    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 已提交
279
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
280 281
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
282
    std::vector<std::string> para = {"UPDATE", "eventNameDemo", "\"type_\":1", "\"key\":230.47"};
M
mamingshuai 已提交
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
    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 已提交
306
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
307 308
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
309
    std::vector<std::string> para = {"TELEPHONY", "eventNameDemo", "\"type_\":1", "\"key\":[230.47]"};
M
mamingshuai 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    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 已提交
331
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
332 333
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
334
    std::vector<std::string> para = {"STARTUP", "eventNameDemo", "\"type_\":1", "\"key\":100"};
M
mamingshuai 已提交
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
    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 已提交
358
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
359 360
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
361
    std::vector<std::string> para = {"SRCTRANSFORMER", "eventNameDemo", "\"type_\":1", "\"key\":[100]"};
M
mamingshuai 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
    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 已提交
383
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
384 385
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
386
    std::vector<std::string> para = {"SENSORS", "eventNameDemo", "\"type_\":1", "\"key\":1000000"};
M
mamingshuai 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
    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 已提交
410
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
411 412
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
413
    std::vector<std::string> para = {"SECURITY", "eventNameDemo", "\"type_\":1", "\"key\":[1000000]"};
M
mamingshuai 已提交
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
    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 已提交
435
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
436 437
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
438
    std::vector<std::string> para = {"ROUTER", "eventNameDemo", "\"type_\":1", "\"key\":10"};
M
mamingshuai 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
    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 已提交
462
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
463 464
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
465
    std::vector<std::string> para = {"POWERMGR", "eventNameDemo", "\"type_\":2", "\"key\":[10]"};
M
mamingshuai 已提交
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
    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 已提交
487
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
488 489
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
490
    std::vector<std::string> para = {"NOTIFICATION", "eventNameDemo", "\"type_\":2", "\"key\":\"abc\""};
M
mamingshuai 已提交
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
    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 已提交
514
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
515 516
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
517
    std::vector<std::string> para = {"MULTIMODALINPUT", "eventNameDemo", "\"type_\":3", "\"key\":[\"abc\"]"};
M
mamingshuai 已提交
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 545 546 547 548
    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 已提交
549
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
550 551
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
552
    std::vector<std::string> para = {"MULTIMEDIA", "eventNameDemo", "\"type_\":3", str};
M
mamingshuai 已提交
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 581 582 583 584
    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 已提交
585
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
586 587
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
588
    std::vector<std::string> para = {"MSDP", "eventNameDemo", "\"type_\":4", str};
M
mamingshuai 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
    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 已提交
613
    RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
M
mamingshuai 已提交
614 615
    string fileinfo = "";
    fileinfo = ReadFile(g_hiLogRedirect);
Z
zhuqingxi 已提交
616
    std::vector<std::string> para = {"LOCATION", "eventNameDemo", "\"type_\":4", g_key, param};
M
mamingshuai 已提交
617 618 619 620 621 622 623 624
    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;
}